javascript - 在另一个守卫解决后,Angular2 运行守卫

标签 javascript angular angular2-routing

在我的项目中,我有两个守卫。 AuthGuard 和 PermissionGuard。我需要首先运行 AuthGuard,当它解决时,如果 permissionGuard 为真,permissionGuard 开始但现在这个守卫并行运行并且 permissionGuard 不能正常工作。我用于此问题的方法是在 Permission guard 中调用 AuthGuard CanActivate 方法,但我认为有更好的方法来执行此操作。

最佳答案

我见过的最好的方法是在子路由上公开路由守卫。这是一个 working example .

{
  path:'', canActivate:[AuthorizationService1], 
    children: [
      {
        path:'', canActivate:[AuthorizationService2],component: HomeComponent
      }
    ]
}

关于javascript - 在另一个守卫解决后,Angular2 运行守卫,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41296998/

相关文章:

javascript - 嵌套的 Angular 子菜单没有正确隐藏

angular - Cdk virtual-scroll inside mat-select for mat-option

authentication - LoggedInOutlet angular2 身份验证 - Router v3.0.0-alpha8 - ComponentInstruction 在哪里?

javascript - Angular - 在调整大小时更改 html 元素

javascript - Angular 错误 : If ngModel is used within a form tag, 必须设置名称属性或

unit-testing - 如何对依赖于 ActivatedRoute 参数的组件进行单元测试?

Angular Router导航和重新加载需要渲染组件一次但渲染两次

javascript - 如何在幻灯片切换中先隐藏div并在单击时显示?

javascript - d3.js 中每一行的多个列值的总和

javascript - ng升级两个版本的Highcharts,错误16