使用setRoot切换到其他应用程序时,Aurelia清除路由历史记录 [英] Aurelia clear route history when switching to other app using setRoot

查看:103
本文介绍了使用setRoot切换到其他应用程序时,Aurelia清除路由历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使使用setRoot()之后,Aurelia路由器也能记住我上一个页面,即使我想再次进入主应用页面,它也会将我重定向到该页面.

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.

我将尝试在用例中对其进行解释. 我有两个应用程序:loginapp. 我登录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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆