The Aurelia router remembers which page I was last on, even after using setRoot() and it will redirect me to that page, even though I would want to land on the main app page again.
I'll try to explain it in a usecase.
I have two apps: login
and app
.
I login in login
app and get redirected to app
.
I navigate to /securedPage
on app
and then proceed to log out and get redirected to login
again.
I login with another user on login
and then I get redirected to app/securedPage
.
I want to be and should be redirected to just app
.
How do I clear the route history when switching between apps with setRoot()?
Wanted to help out, recently got this working and the suggestions above almost work, but they are missing some parts. In this thread, the creator of Aurelia (Eisenberg) repsonds with a suggestion:
https://github.com/aurelia/framework/issues/590
So to switch app root do the following:
this.router.navigate('/', { replace: true, trigger: false });
this.router.reset();
this.router.deactivate();
this.aurelia.setRoot('app');
In my case I could actually skip the reset and deactivate part and just do
this.router.navigate('/', { replace: true, trigger: false });
However doing this.router.navigate('/') without the replace and trigger part caused problems especially when switching app root multiple times.
So make sure to add:
... { replace: true, trigger: false });
did you try
this.router.deactivate();
this.router.reset();
this.app.setRoot('app');
It is not pretty but this this did the trick for me:
router.navigate("/");
aurelia.setRoot("login")