我在app-routing模块中获得了这些路由:
{
path: 'some',
canActivate: [AuthGuard],
data: {
auth: {
test: "theTest"
},
},
children: [
{
path: '',
pathMatch: 'full',
component: SomeComponent,
canActivate: [AuthGuard],
resolve: {
something: SomethingResolver
}
},
]
}
在AuthGuard CanActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
中,如果我执行console.log(route.data["auth"]
并获得{test: "theTest"}
两次。
孩子们采取"采取"父母的数据?
答案 0 :(得分:0)
你是重复的东西,children数组中的path : 'some'
和path: ''
指向同一路径,只将canActivate: [AuthGuard]
放在子节点中,以便执行canActivate
只有一次:
{
path: 'some',
data: {
auth: {
test: "theTest"
}
},
children: [
{
path: '',
pathMatch: 'full',
component: SomeComponent,
canActivate: [AuthGuard],
resolve: {
something: SomethingResolver
}
},
]
}