SnoopDougg
SnoopDougg

Reputation: 1609

For Angular2 Router3, why isn't my Parent Route's Guard called every time I switch between its child routes?

I have a Guard for my parent route that isn't always called when viewing the child routes. It is called when the first child is loaded, but if I switch to another child within the same parent, the parent's Guard isn't referenced again. Here's what I have:

export const AppRoutes: RouterConfig = [
    {
        path: 'app',
        component: AppComponent,
        canActivate: [LoggedInGuard],
        children: [
            {path: 'child1', component: Child1Component, canActivate: [AuthGuard]},
            {path: 'child2', component: Child2Component, canActivate: [AuthGuard]},
            {path: 'error/:status', component: ErrorComponent}
        ]
    }
];

Is there a way to make sure LoggedInGuard is called every time I switch between child1 and child2?

Upvotes: 2

Views: 196

Answers (1)

Niyaz
Niyaz

Reputation: 2893

canActivateChild: [LoggedInGuard] 

Is arrived , so you can achieve this by canActivateChild of router.

Upvotes: 1

Related Questions