Angular 2路线:不为儿童呼吁解决 [英] Angular 2 routes: resolve not called for children
本文介绍了Angular 2路线:不为儿童呼吁解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用:
"@angular/core": "2.2.2",
"@angular/router": "3.2.2",
路线如下:
export const rootRouterConfig: Routes = [
{
path: '', resolve: { profile: PrefetchProfileService },
children: [
{path: '', component: Pages.LandingComponent, pathMatch: 'full'},
{path: 'pl', component: PersonalLoanComponent},
{path: 'login', component: Pages.LoginComponent, canActivate: [ExistingSessionGuard]},
{path: 'register', component: Pages.RegisterComponent, canActivate: [ExistingSessionGuard]},
{path: 'home', component: Pages.HomeComponent, canActivate: [AuthGuard]},
]
}
];
问题在于,解析不会触发任何直接导航到子路径的操作.例如:如果用户直接导航到/login,则不会调用PrefetchProfileService.如果用户导航到/,然后转到/login,则一切正常.我该如何正确处理?
The issue is that resolve is not triggering for any direct navigation to a child path. Ex: if user navigates directly to /login, PrefetchProfileService is not called. If user navigates to /, then goes to /login, everything is fine. How do I deal with this correctly?
推荐答案
您必须在要使用PrefetchProfileService的每个子路由中添加resolve.
You have to add resolve in each child route you want to use PrefetchProfileService.
path: '', resolve: { profile: PrefetchProfileService },
children: [
{path: '', component: Pages.LandingComponent,resolve: { profile: PrefetchProfileService } ,pathMatch: 'full'},
{path: 'pl', resolve: { profile: PrefetchProfileService },component: PersonalLoanComponent},
{path: 'login', resolve: { profile: PrefetchProfileService },component: Pages.LoginComponent, canActivate: [ExistingSessionGuard]},
{path: 'register', resolve: { profile: PrefetchProfileService },component: Pages.RegisterComponent, canActivate: [ExistingSessionGuard]},
{path: 'home',resolve: { profile: PrefetchProfileService } ,component: Pages.HomeComponent, canActivate: [AuthGuard]}
,
这篇关于Angular 2路线:不为儿童呼吁解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文