2016-12-12 1 views
0

Использование:Угловые 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, все в порядке. Как мне с этим справиться?

ответ

1

Вы должны добавить решение в каждый дочерний маршрут, который вы хотите использовать 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]} 

, 
+0

Спасибо, это работает, но очень раздражает множество маршрутов. Это также противоречит тому, как работают охранники (применяются параллельно, начиная с самого верхнего родителя). В итоге я сделал свою предварительную выборку с охранником :( –

Смежные вопросы