I am setting a guard in creditscore childpages but it seems that it is not working. I am trying to redirect back to /creditscore
page if user is not authenticated, But when i access /crediscore/verification
page it is not redirecting back to /creditscore
page even if guard is enabled.
I have tried this code below.
const routes: Routes = [
{
path: '**',
component: CreditScoreComponent,
resolve: { config: WPConfigResolver },
children: [
{
path: 'verification',
component: CreditScoreSelectorComponent,
canActivate: [ResultsGuard],
},
{
path: 'results',
component: CreditScoreResultsComponent,
canActivate: [ResultsGuard],
}
]
}
];
export const routing: ModuleWithProviders = RouterModule.forChild(routes);
This is my results.guard.ts
canActivate(): boolean {
if (this.authService.isAuthenticatedUser()) {
return true;
} else {
this.router.navigate(['/creditscore']);
return false;
}
}
Is this the correct way? Thanks in advance.