我正在尝试根据当前登录用户的角色向我的应用程序路由文件中的所有路由动态添加声明。角色的详细信息位于我正在app.component.ts中读取的JSON文件中。如何在防止循环依赖的同时读取文件并动态设置声明的优先级?
目前,我已经为角色属性提供了一些默认值,以设置需要动态设置的声明
```
//Custom Claim Example
const commonCondition = () => pipe(customClaims,
map(claims => {
if (!claims || claims.length == 0) {
return [`/login`];
}
if (claims['admin'] == true) {
return true;
} else if (claims['alpha'] == true) {
return ['/create-alpha'];
} else if (claims['beta'] == true) {
return [`/create-beta`];
} else {
return [`/login`];
}
})
);
Router Example
[
{
path: 'create-candidate',
loadChildren: './candidate/create-candidate/create-
candidate.module#CreateCandidatePageModule',
canActivate: [AngularFireAuthGuard],
data: { authGuardPipe: commonCondition }
},
]
** NOTE** The terms 'admin', 'alpha','beta' are the roles that need to be set dynamically by reading a json file and some other operations ..
Using hard coded values it working well . Need a solution for handling the same dynamically using claims only.