In our project, I have to implement a navigation or redirect to a maintenance page, if maintenance mode is activated. I wanted to do this in the AuthGuard service, and do something like:
canActivate(...) {
if (this.inMaintenance()) {
this._navController.navigateForward('settings-maintenance', { replaceUrl: true });
return false;
}
}
unfortunately, the project routes settings are like this:
const routes: Routes = [
{
path: '',
loadChildren: () => import('./template/template.module').then((module) =>
module.TemplatePageModule),
canActivate: [AuthGuard],
},
{
path: 'settings-maintenance',
pathMatch: 'full',
component: SMaintenanceComponent,
},
{
path: ':id',
loadChildren: () => import('./template/template.module').then((module) =>
module.TemplatePageModule),
canActivate: [AuthGuard],
},
{
path: ':id/:params',
loadChildren: () => import('./template/template.module').then((module) => module.TemplatePageModule),
canActivate: [AuthGuard],
},
];
so, whenever I try to navigate to settings-maintenance, it will hit the route-guard again because it thinks it is path: ':id'
. Is there a way to avoid this?
I wanted to avoid to show the login page and directly redirect to the SMaintenance Page without login, but no Idea how to do it..
Otherwise, I will have to check for maintenance mode in the footer or so and then do a redirect there after the login...