Aurelia clear route history when switching to othe

2019-01-25 19:53发布

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()?

3条回答
时光不老,我们不散
2楼-- · 2019-01-25 20:24

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 });
查看更多
我只想做你的唯一
3楼-- · 2019-01-25 20:40

It is not pretty but this this did the trick for me:

router.navigate("/");
aurelia.setRoot("login")
查看更多
倾城 Initia
4楼-- · 2019-01-25 20:46

did you try

this.router.deactivate();
this.router.reset();
this.app.setRoot('app');
查看更多
登录 后发表回答