I actually got multiple guard which share the same exact data called from my API.
My guards look like that :
export class GuardBlockAgent implements CanActivateChild {
...
canActivateChild(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | boolean {
return this.userService.retrieveMyUser(null, environment.liveMode).map(
...
)}
I am looking for a way to share my data between my guards. Instead of making multiple call for the same data.
In this post they use this way with canActivate
{ path: 'super-user-stuff', component: SuperUserStuffComponent, canActivate: RoleGuard, data: {roles: ['SuperAdmin', ...]} }
But how to pass dynamic data which comes from my API ?
theme-routing.module.ts
const routes: Routes = [
{
"path": "",
"component": ThemeComponent,
"resolve": { me: AgentResolver },
"canActivate": [AuthGuard],
"children": [
{
"path": "...",
"loadChildren": "...",
"canActivateChild": [GuardBlockAgent]
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ThemeRoutingModule { }
EDIT: localStroage are not safe, that's why I prefer not to use it.