Answer the question
In order to leave comments, you need to log in
How to implement role model in Angular?
How to correctly implement routes depending on the role? At the moment, the universal page is news where all authorized users go, but users with a certain role must go to another section.
cabinet.routing.ts file:
const cabinetRoutes: Routes = [
{ path: '', redirectTo: 'news', pathMatch: 'full' },
{ path: '', component: LayoutComponent, children: [
{ path: 'news', loadChildren: () => import('./modules/news/news.module').then(m => m.NewsModule) },
{ path: 'analytics', loadChildren: () => import('./modules/analytics/analytics.module').then(m => m.AnalyticsModule) },
{ path: 'declaration', loadChildren: () => import('./modules/declaration/declaration.module').then(m => m.DeclarationModule) },
{ path: 'directory', loadChildren: () => import('./modules/directory/directory.module').then(m => m.DirectoryModule) },
{ path: 'documents', loadChildren: () => import('./modules/documents/documents.module').then(m => m.DocumentsModule) },
{ path: 'reestr', loadChildren: () => import('./modules/reestr/reestr.module').then(m => m.ReestrModule) },
{ path: 'orgInformation', loadChildren: () => import('./modules/org-information/org-info.module').then(m => m.OrgInfoModule) },
{ path: 'dashboard', loadChildren: () => import('./modules/dashboard/dashboard.module').then(m => m.DashboardModule) },
{ path: 'admin', loadChildren: () => import('./modules/admin/admin.module').then(m => m.AdminModule) },
],
},
];
...
this.authService.sendSignedPhraseToServer(this.signedCert).subscribe( responseWithJWT => {
localStorage.setItem('someKey', responseWithJWT.token);
this.user = this.authService.getToken;
this.user = jwt_decode(this.user);
this.router.navigate(['/cabinet']);
});
const appRoutes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'cabinet' },
{
path: 'auth',
loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule),
},
{
path: 'cabinet',
loadChildren: () => import('./modules/cabinet/cabinet.module').then(m => m.CabinetModule),
canLoad: [AuthGuard],
},
];
Answer the question
In order to leave comments, you need to log in
How to write a routing so that when .....
.... to have a redirect to different pages during authorization?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question