使用 setRoot 切换到其他应用程序时,Aurelia 清除路线历史记录 [英] Aurelia clear route history when switching to other app using setRoot
问题描述
Aurelia 路由器会记住我上次访问的页面,即使在使用 setRoot() 之后,它也会将我重定向到该页面,即使我想再次登陆主应用程序页面.
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.
我将尝试在用例中解释它.我有两个应用程序:login
和 app
.我登录 login
应用程序并被重定向到 app
.我导航到 app
上的 /securedPage
,然后继续注销并再次重定向到 login
.我在 login
上与另一个用户登录,然后我被重定向到 app/securedPage
.我想并且应该被重定向到 app
.
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
.
如何在使用 setRoot() 切换应用程序时清除路由历史记录?
How do I clear the route history when switching between apps with setRoot()?
推荐答案
想帮忙,最近得到了这个工作和上面的建议几乎工作,但他们缺少一些部分.在此线程中,Aurelia (Eisenberg) 的创建者回复了一个建议:https://github.com/aurelia/framework/issues/590
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 });
但是在没有替换和触发部分的情况下执行 this.router.navigate('/') 会导致问题,尤其是在多次切换应用根目录时.
However doing this.router.navigate('/') without the replace and trigger part caused problems especially when switching app root multiple times.
所以一定要添加:
... { replace: true, trigger: false });
这篇关于使用 setRoot 切换到其他应用程序时,Aurelia 清除路线历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!