在canActivate中获取父路线参数

时间:2017-09-16 20:29:47

标签: angular routes parent router canactivate

我这样的路线:

[
  {
    path: ':orgName',
    children: [
      {
        path: '',
        component: HomeComponent
        canActivate: [AuthGuard],
      },
      {
        path: 'details',
        component: DetailComponent
      }
    ]
  }
]

如何在AuthGuard的canActivate中访问orgName?

我试过

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    console.log(route.params["orgName"])
}

但它打印未定义的

1 个答案:

答案 0 :(得分:3)

要访问父母的参数,请尝试: -

route.parent.params["orgName"]