美文网首页
Angular监听路由变化

Angular监听路由变化

作者: Bager | 来源:发表于2020-05-22 08:41 被阅读0次
 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);
        }
    });
}

相关文章

网友评论

      本文标题:Angular监听路由变化

      本文链接:https://www.haomeiwen.com/subject/rupfahtx.html