Aurelia clear route history when switching to other app using setRoot

最后都变了- 提交于 2019-11-28 01:33:38

问题


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


回答1:


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 });



回答2:


did you try

this.router.deactivate();
this.router.reset();
this.app.setRoot('app');



回答3:


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

router.navigate("/");
aurelia.setRoot("login")


来源:https://stackoverflow.com/questions/36247052/aurelia-clear-route-history-when-switching-to-other-app-using-setroot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!