我有以下路线配置:
export const AppRoutes: Routes = [
{
path: 'secure', component: SecureInformationComponent, data: { permission: 'view_secure_information'}
}
]
是否可能禁用/启用使用routerLink指令的每个元素,无论用户是否具有'view_secure_information'权限?如:
<a [routerLink]="['secure']">Go to secure area of the application</a>
我想到的唯一可能的解决方案是实现一个CanActivate防护,它根据路径中的数据进行检查。 但我还必须在每个[routerLink]附加的锚点或按钮上添加导航到此安全路由的另一个指令,该指令执行相同的检查并禁用/启用该元素,例如:
<a [routerLink]=['secure']" *hasPermission="view_secure_information">Go to secure area of the application</a>
虽然这样可行,但我会有冗余代码,并且检查非常分散。