I got stuck recently with Angular route guards. CanActive runs only once when the page is loaded and does not run on route change within the guarded route. I think this was changed because it used to run on each change. From what I read in forums, I should use CanActivateChild. The thing is, our application consists of several modules, that have several route descendants and when I use CanActivateChild in root module, it is called several times when changing the route.
I find it dumb to assign a guard to each child because, for AppModule, those lazy loaded child modules should be just 'Black Boxes' and I wanted to define that all those modules should be guarded.
export const routes: Routes = [
{
path: '404',
component: NotFoundComponent
},
{
path: '',
canActivate: [AuthGuard],
component: FullLayoutComponent,
data: {
title: 'Home'
},
children: [
{
path: 'administration',
loadChildren: './administration/administration.module#AdministrationModule'
},
{
path: 'settings',
loadChildren: './settings/settings.module#SettingsModule'
}
]
},
{
path: '',
loadChildren: './account/account.module#AccountModule'
},
{
path: '**',
redirectTo: '404'
}
];
Is there any solution to this? Or do You find this as 'not an issue' regarding security?
Thank You all.