angular2 routing - Using a base guard for all routes in Angular 2 application -
is there way set "base" canactivate
when configuring routes in angular2? routes covered same base check, , each route can have more granular check.
i have appmodule
routing this:
@ngmodule({ imports: [ routermodule.forroot([ { path: '', component: homecomponent, canactivate: [authenticationguardservice], data: { roles: [roles.user] } } ]) ], exports: [ routermodule ] }) export class approutingmodule { }
and feature module featuremodule
:
@ngmodule({ imports: [ routermodule.forchild([ { path: "feature", component: featurecomponent, // i'd avoid having this: canactivate: [authenticationguardservice], data: { roles: [roles.user] } } ]) ], exports: [ routermodule ] }) export class featureroutingmodule { }
i let authenticationguardservice
check if user has access route using roles provided in data
.
can avoid having set canactivate
, data
in feature routing modules? i'd configure "base" canactivate
routes in application.
const routes: routes = [ { path: '', canactivate: [authguard], children: [ { path: '', component: homecomponent }, { path: 'builds', component: buildscomponent }, { path: 'files', component: filescomponent }, { path: 'publications', component: publicationscomponent } ] }, { path: 'login', component: logincomponent }, { path: '**', redirectto: '' } ];
Comments
Post a Comment