【发布时间】:2020-05-27 12:00:57
【问题描述】:
我的应用中有一个侧边菜单,可以很好地显示活动链接。我唯一的问题是当我最初运行应用程序时,活动链接没有突出显示。我订阅了RouterConfigLoadEnd 事件来设置选定的链接,但我认为这不是正确的方法,因为如果我导航到另一个链接,它将继续设置它。有什么建议吗?
constructor(private router: Router) {
const initialPage = this.router.events.subscribe((event: RouteConfigLoadEnd) => {
console.log('inital load');
this.selectedPath = '/menu/forecast';
});
// Tried to unsub here but then the active link will not be active at start
// initalPage.unsubscribe();
this.router.events.subscribe((event: RouterEvent) => {
if (event && event.url) {
console.log('set active');
this.selectedPath = event.url;
}
});
}
【问题讨论】:
标签: angular ionic-framework angular-ui-router ionic4