相关疑难解决方法(0)

多个canActivate防护装置在第一次失败时全部运行

我有一个有两名canActivate守卫的路线(AuthGuardRoleGuard).first(AuthGuard)检查用户是否已登录,如果没有,则重定向到登录页面.第二个检查用户是否具有允许查看页面的角色定义,如果没有,则重定向到未授权页面.

canActivate: [ AuthGuard, RoleGuard ]
...
export class AuthGuard implements CanActivate {
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
        ...
        this.router.navigate(['/login']);
        resolve(false);
}

export class RoleGuard implements CanActivate {
    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
        ...
        this.router.navigate(['/unauthorized']);
        resolve(false);
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我访问路线并且我没有登录时,我点击了AuthGuard,它失败并告诉路由器导航到/login.然而,即使AuthGuard失败RoleGuard了,然后运行然后导航到/unauthorized.

在我看来,如果第一个失败,那么运行下一个后卫是毫无意义的.有没有办法强制执行此行为?

routing typescript angular2-routing angular

29
推荐指数
5
解决办法
2万
查看次数

Angular 2如何在同一路径上应用具有Or-Relationship的多个防护

我的应用程序允许基于用户角色访问内容.我为每个角色写了一个Router Guard.某些内容允许访问role1或role2或role3.我应该如何在feature-routing.module.ts文件中编写canActivate声明?据我了解,如果我写

canActivate:[Role1Guard, Role2Guard, Role3Guard]
Run Code Online (Sandbox Code Playgroud)

如果任何警卫返回false,则拒绝访问.但在我的情况下,如果任何一个守卫返回true,我应该允许访问.怎么做?提前谢谢了!

angular2-routing angular2-guards angular

13
推荐指数
1
解决办法
4136
查看次数

Angular 2 Router Guards命令

可以在阵列中定义Angular 2路由器防护装置.例如:

<code>
 canActivate: ['CanAlwaysActivateGuard','AuthGuard']
</code>
Run Code Online (Sandbox Code Playgroud)

以下是我的问题:

  1. 两个警卫的执行顺序是什么.
  2. 如果我想仅在CanAlwaysActivateGuard返回true时才执行AuthGuard,那么这是可能的.

angular2-routing angular

8
推荐指数
3
解决办法
3440
查看次数

如何在Angular等待守卫

如果我在路线上指定三名警卫,似乎所有警卫都会立即进行评估.

{path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]}

我遇到的问题是我不希望GuardTwo在GuardOne完成之前运行.有没有办法实现这个目标?

javascript rxjs rxjs5 angular

7
推荐指数
1
解决办法
2237
查看次数