我想根据当前路线不同地显示我的一个角度分量。为此,我在组件中设置了对NavigationEnd
的订阅。但是,此组件似乎仅在导航结束后才被初始化,因此从不调用它。代码如下:
constructor(private store: Store<fromApp.AppState>, private router: Router) {
}
subscribeToNavigation() {
console.log('Setting up navigation subscription');
const navEnd = this.router.events.pipe(
filter(evt => evt instanceof NavigationEnd)
) as Observable<NavigationEnd>;
this.navEndSubscription = navEnd.subscribe(evt => {
console.log('Finished navigating to: ' + evt.url);
});
console.log('done');
}
我在听NavigationEnd
事件时走错了方向吗?