Multiple canActivate guards all run when first fails

前端 未结 6 1282
借酒劲吻你
借酒劲吻你 2020-12-02 15:32

I have a route with two canActivate guards (AuthGuard and RoleGuard). The first (AuthGuard) checks to see if the user is

6条回答
  •  一个人的身影
    2020-12-02 16:24

    Currently having multiple async guards(returning Promise or Observable) will run at the same time. I opened a issue for this: https://github.com/angular/angular/issues/21702

    Another workaround to the described solution above is to use nested routes:

    {
      path: '',
      canActivate: [
        AuthGuard,
      ],
      children: [
        {
          path: '',
          canActivate: [
            RoleGuard,
          ],
          component: YourComponent
          // or redirectTo
          // or children
          // or loadChildren
        }
      ]
    }
    

提交回复
热议问题