【发布时间】:2018-03-22 23:23:46
【问题描述】:
我想在子路由器上授权路由,但我对当前的解决方案并不满意。我当前的路线如下所示:
/
/account
/account/signin
/account/signout
为了实现这一点,我为帐户页面定义了两个路由器 - 一个根路由器和一个子路由器。为了在我的帐户子路由器上授权路由,我将以下管道步骤添加到我的根路由器配置中。
config.addAuthorizeStep({
run: (instruction: NavigationInstruction, next: Next): Promise<any> => {
if (!this.auth.isAuthenticated && (instruction.fragment === '/account' || instruction.fragment === '/account/profile')) {
return next.cancel(new Redirect('account/signin'))
}
if (this.auth.isAuthenticated && instruction.fragment === '/account/signin') {
return next.cancel(new Redirect('account'))
}
if (this.auth.isAuthenticated && instruction.fragment === '/account/signup') {
return next.cancel(new Redirect('account'))
}
return next();
}
})
它有效,但我觉得必须有更好的方法......我真的很想完成以下工作:
- 将授权逻辑移至帐户子路由器。
- 使用路由名称而不是片段,因为它看起来更健壮
【问题讨论】:
-
我强烈推荐使用多个 shell 或 root。在这里查看我的文章:davismj.me/blog/aurelia-login-best-practices-pt-1
-
这真的很酷!肯定会进一步使用多个外壳。谢谢!
标签: aurelia