private router: Router,
// 声明订阅对象
rooterChange: Subscription;
ngOnDestroy() {
if (this.rooterChange) {
this.rooterChange.unsubscribe();
}
}
/**
* 监听路由变化
*/
listenRouterChange() {
this.rooterChange = this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
console.log(event.url);
}
});
}
网友评论