使用setRoot切换到其他应用程序时,Aurelia清除路线历史记录

Tra*_*avo 4 aurelia aurelia-router

Aurelia路由器会记住我最后一个页面,即使在使用setRoot()之后,它也会将我重定向到该页面,即使我想再次登陆主应用程序页面.

我将尝试在用例中解释它.我有两个应用程序:loginapp.我在loginapp中登录并被重定向到app.我浏览到/securedPageapp,然后进行注销并重定向到login一次.我与另一个用户登录,login然后我被重定向到app/securedPage. 我想成为并且应该被重定向到app.

使用setRoot()切换应用程序时,如何清除路径历史记录?

小智 7

想要帮忙,最近得到了这个工作,上面的建议几乎工作,但他们缺少一些部分.在这个帖子中,Aurelia(Eisenberg)的创建者回复了一个建议:https: //github.com/aurelia/framework/issues/590

所以要切换app root,请执行以下操作:

    this.router.navigate('/', { replace: true, trigger: false });
    this.router.reset();
    this.router.deactivate();

    this.aurelia.setRoot('app');
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我实际上可以跳过重置和停用部分,只是做

    this.router.navigate('/', { replace: true, trigger: false });
Run Code Online (Sandbox Code Playgroud)

但是,在没有替换和触发器部分的情况下执行this.router.navigate('/')会导致问题,尤其是在多次切换app root时.

所以一定要添加:

     ... { replace: true, trigger: false });
Run Code Online (Sandbox Code Playgroud)