来自其他应用程序根目录的路由器authorizeStep不断触发 [英] Router authorizeStep from other app root keeps triggering

查看:51
本文介绍了来自其他应用程序根目录的路由器authorizeStep不断触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Aurelia项目分为两个应用程序根目录,两个都有其自己的路由结构. 应用程序根目录1包含无需身份验证的所有屏幕(登录,重置密码等).应用程序根目录2的所有其他屏幕.

My Aurelia project is split up in 2 app roots, both with their own route structure. App root 1 contains all screens where you don't have to be authenticated (login, reset pwd,...) App root 2 all the other screens.

当您未通过authorizeStep进行身份验证时,我将阻止访问应用程序根2上的路由.在此步骤中,如果您未通过身份验证,则将根目录设置为应用程序根目录1.应用程序根目录1具有作为默认路由的登录视图,因此可以很好地工作.因此,当您未通过身份验证并尝试导航到应用程序根目录2中的深层网址时,就会发生这种情况:

I'm blocking access to routes on app root 2 when you are not authenticated with an authorizeStep. In this step, I set the root to app root 1 when you are not authenticated. App root 1 has a login view as default route, so this works quite well. So, when you are not authenticated and try to navigate to a deep url in app root 2, this happens:

  1. App Root 2配置其路由并尝试导航到深层URL
  2. authorizeStep触发,您未通过身份验证,路由被取消并且aurelia.setRoot()发生在应用程序根目录1
  3. 应用程序根目录1配置其路由器,并将您导航到默认路由登录页面

问题是手动注销.单击位于应用程序根目录2中的此按钮时.我清除了用户数据,因此您不再通过身份验证.完成此步骤后,我将根手动设置为应用程序根1,然后出现无限循环:

The problem is manually logging out. When this button, residing in app root 2, is clicked. I clear user data, therefore you are not authenticated anymore. Following that step, I manually set the root to app root 1, and there I get an infinite loop:

  1. 应用程序根目录1配置其路由器,并将您导航到默认路由登录页面
  2. authorizeStep从应用程序根2!触发,您未通过身份验证,路由被取消,并且aurelia.setRoot()发生在应用程序根1
  3. 应用程序根目录1配置其路由器,并将您导航到默认路由登录页面
  4. ...

问题是从根2导航到authorizeStep时,在根1导航时会触发.我在寻找一种删除authorizestep的方法,但是我不认为框架当前会公开这一点.我很好奇,这个问题仅在单击注销,深层链接和重定向到登录按预期工作时才会发生.

The problem is that the authorizeStep from root 2 triggers when navigating in root 1. I looked for a way for removing the authorizestep, but I don't think the framework currently exposes this. I find it very curious that this issue only occurs when clicking logout, deep linking and redirecting to login works as expected.

为清楚起见,我创建了一个可重现的要点,单击注销按钮,您将看到控制台无限地重复Authorize步骤.

I created a reproducable gist for clarity, click the logout button and you will see the console infinitely repeating the authorizestep.

https://gist.run/?id=1a551dcc4bec7d191ab680a937b19cfc

推荐答案

原来,您需要自己清除这些步骤,而在aurelia.setRoot()内部调用的router.clear()中并不需要这样做.

Turns out you need to clear the steps yourself, this isn't done in a router.clear(), which the aurelia.setRoot() internally calls.

幸运的是,您实际上可以自己执行以下操作: this.pipelineProvider.reset();

Fortunately you actually can do this yourself, with: this.pipelineProvider.reset();

虽然我发现此行为不合逻辑,所以为此创建了一个问题: https ://github.com/aurelia/router/issues/465

I don't find this behavior logical though, so I created an issue for it: https://github.com/aurelia/router/issues/465

这篇关于来自其他应用程序根目录的路由器authorizeStep不断触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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