我正在使用API调用检查是否有权限来限制路由。当前的路由是
{
path: '',
children: [
{ path: '', component: HomeComponent},
{ path: ':id', component: HomeComponent },
{ path: 'unauthorized', component: UnauthorizedComponent },
{ path: '**', redirectTo: '' }
]
}我想要的是用防护限制boh、''和:id,在其中我重新路由到unauthorized,但是如果我将canActivate应用到根路径,它会导致循环调用,因为它重定向到unauthorized,它也是防护的,它会阻塞UI。如果我将它应用于我想要保护的孩子,它不会被调用。
发布于 2019-03-19 21:14:34
{
path: '',
children: [
{ path: '', canActivate: [WhateverService], children: [
{ path: '', component: HomeComponent},
{ path: ':id', component: HomeComponent },
]},
{ path: 'unauthorized', component: UnauthorizedComponent },
{ path: '**', redirectTo: '' }
]
}这应该能起到作用。这只是基本的路由分组。
https://stackoverflow.com/questions/55241826
复制相似问题