angular - 如何在 Angular 2/5 中从 RouterLinkWithHref 中找到匹配的路由?
问题描述
我正在尝试使用指令隐藏/删除菜单/子菜单项。
我正在使用@ContentChild 阅读RouterLinkWithHref,但找不到Route。我有兴趣阅读路线中提供的数据对象。
下面是一些更有意义的代码。让我知道,如果有什么有用的答案或深入挖掘。
@Directive({
selector: '[roleCheck]'
})
export class RoleCheckDirective implements AfterViewInit {
@ContentChild(RouterLinkWithHref) routerLinkWithHref: RouterLinkWithHref;
constructor(private elementRef: ElementRef) { }
ngAfterViewInit() {
console.log(this.routerLinkWithHref);
// do something here to find matched route, and read route.data for allowed roles
}
}
主路线下方有包含角色的数据。Angular 如何从 RouterLink 和 RouterLinkWithHref 中找到匹配的路由。Angular 还提供 RouterLinkActive 必须读取 RouterLink/RouterLinkWithHref 才能在导航菜单中显示活动路由。所以,问题是如何,哪些方法可用。我怎么能看到他们的实施。我正在使用带有打字稿的角度。我看过RouterLinkActive的类型。任何帮助表示赞赏。
const routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent, data: { roles: ['Admin', 'Analyst']} },
...
];
解决方案
推荐阅读
- oracle - 为什么我无法在 oraclecloud 的 Always Free 计划中创建第二个 amd 实例?
- java - 有没有办法在不使用参数的情况下在另一种方法中使用变量?
- android-studio - Gradle 不工作,下载位置不工作
- java - 如何导入 .p7b 根证书红帽服务器
- snowflake-cloud-data-platform - 使用 IICS 加载带有时间戳的平面文件
- ios - MapBox Maps iOS SDK:有没有办法在 PointAnnotation 被选中时对其进行动画处理
- python - 打印并将相同的变量附加到列表时,我得到了不同的值,这是为什么呢?
- sql - 我想更新表中的字符串
- php - 我是否需要在 MOODLE 中开发一个新功能来获得一个通过使用考勤插件返回会话列表的 Web 服务?
- jwt - Quarkus 同时使用 Authorization 和 Cookie 进行 jwt 授权