首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不重复"CanActivate“属性的角路由中的CanActivate保护

不重复"CanActivate“属性的角路由中的CanActivate保护
EN

Stack Overflow用户
提问于 2020-09-10 05:22:56
回答 1查看 413关注 0票数 0

我希望在路由过程中使用canActivate保护,而不重复

canActivate: AuthGuard,

代码如下

代码语言:javascript
复制
import { AuthGuard } from 'src/app/core/guards/auth.guard';
 
const routes: Routes = [{
  path: '', data: { title: 'Users' },
  children: [
    {
          path: 'createuser',
          canActivate: [AuthGuard],
          component: UserComponent,
          data: { title: 'Create User' }
        },
     {
          path: 'updateuser',
          canActivate: [AuthGuard],
          component: UpdateUserComponent,
          data: { title: 'Update User' }
        },
  ]
}];
EN

回答 1

Stack Overflow用户

发布于 2020-09-10 05:29:39

在您的示例中,您可以使用canActivateChild

代码语言:javascript
复制
import { AuthGuard } from 'src/app/core/guards/auth.guard';
 
const routes: Routes = [{
  path: '', data: { title: 'Users' },
  canActivateChild: [AuthGuard],
  children: [
    {
          path: 'createuser',
          component: UserComponent,
          data: { title: 'Create User' }
        },
     {
          path: 'updateuser',
          component: UpdateUserComponent,
          data: { title: 'Update User' }
        },
  ]
}];

所以这个守卫将适用于所有的孩子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63823287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档