我在应用程序路由模块中得到了这些路线:
{
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"}
两次。
孩子是否"采用"父母的数据?
您正在复制事物,儿童数组中的path : 'some'
和path: ''
指向同一路线,仅将canActivate: [AuthGuard]
放入孩子中,因此canActivate
仅执行一次:
{
path: 'some',
data: {
auth: {
test: "theTest"
}
},
children: [
{
path: '',
pathMatch: 'full',
component: SomeComponent,
canActivate: [AuthGuard],
resolve: {
something: SomethingResolver
}
},
]
}