Reputation: 837
Using:
"@angular/core": "2.2.2",
"@angular/router": "3.2.2",
Routes look like:
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]},
]
}
];
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?
Upvotes: 0
Views: 1092
Reputation: 236
You can also just use runGuardsAndResolvers: "always" at your parent route
Upvotes: 0
Reputation: 409
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]}
,
Upvotes: 1