路由上的 Angular2 路由器数据 属性
Angular2 Router data property on routes
我的 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"}
两次。
做 children "adopt" parents 的数据?
你在复制东西,子数组中的 path : 'some'
和 path: ''
指向相同的路由,只在子数组中放置 canActivate: [AuthGuard]
所以 canActivate
会只执行一次:
{
path: 'some',
data: {
auth: {
test: "theTest"
}
},
children: [
{
path: '',
pathMatch: 'full',
component: SomeComponent,
canActivate: [AuthGuard],
resolve: {
something: SomethingResolver
}
},
]
}
我的 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"}
两次。
做 children "adopt" parents 的数据?
你在复制东西,子数组中的 path : 'some'
和 path: ''
指向相同的路由,只在子数组中放置 canActivate: [AuthGuard]
所以 canActivate
会只执行一次:
{
path: 'some',
data: {
auth: {
test: "theTest"
}
},
children: [
{
path: '',
pathMatch: 'full',
component: SomeComponent,
canActivate: [AuthGuard],
resolve: {
something: SomethingResolver
}
},
]
}