I have an question about Angular 5 routing.
If I declare routes like this below, the route guard
is called every time I route to one of the components via routerLink
in html.
const routes: Route[] = [
{ path: 'comp1', component: Comp1Component, canActivate: [AuthGuard]},
{ path: 'comp2', component: Comp2Component, canActivate: [AuthGuard]},
{ path: '', component: HomeComponent, canActivate: [AuthGuard]},
]
But if I declare it with a componentless
route, the guard is only called when the app starts. And when I switch routes in html the guard is never called again.
const routes: Route[] = [
{ path: '', canActivate: [AuthGuard], children: [
{ path: 'comp1', component: Comp1Component},
{ path: 'comp2', component: Comp2Component}
]}
Why is the route guard in my scenario with componentless parent route not called every time a route to a component?
AuthGuard
will be invoked ? – Ritwick DeyAuthGuard
is also not called again. Why is that? Is it because there is no other route at the same level as the parent route? – ochs.tobi