Angular监听路由变化

2020-05-22  本文已影响0人  Bager
 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);
        }
    });
}
上一篇 下一篇

猜你喜欢

热点阅读