我有以下路由配置:

export const AppRoutes: Routes = [
  {
    path: 'secure', component: SecureInformationComponent, data: { permission: 'view_secure_information'}
  }
]

无论用户是否具有'view_secure_information'权限,是否可能禁用/启用使用routerLink指令的每个元素?如:

<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>

虽然这可行,但我会有冗余代码,并且检查是非常分散的 .