I have a guard that redirects the user to tabs
page if user has been authenticated else redirects to home
(login) page.
Now on a particular operation, my backend express server redirects the user to order-success
page. But logic in the guard doesn’t allow the user to be redirected to order-success
page instead user gets redirected to tabs
page
So how to bypass this url in the guard so that user will go to order-success
page
Thank you in advance
auth.guard.ts
export class AuthGuard implements CanActivate {
constructor(public auth: AuthenticationService, public router : Router,) {}
async canActivate(): Promise<boolean> {
let auth = await this.auth.isAuthenticated() // returns true if user is authenticated else false
if(auth) {
return true;
}
else {
this.router.navigate(['home'])
return false;
}
}
}
app-routing.module.ts
{ path: '', redirectTo: 'tabs', pathMatch: 'full' },
{
path: 'tabs', canActivate: [AuthGuard],
loadChildren: () => import('./pages/tabbar/tabbar.module').then( m => m.TabbarPageModule)
},
{
path: 'order-success',
loadChildren: () => import('./pages/order-success/order-success.module').then(m => m.OrderSuccessPageModule)
},