// 声明订阅对象
routerChange: Subscription;

// 发生变化是才会触发,初始化时不会触发
ngOnInit() {
  this.routerChange = this.router.events.subscribe((event) => {
    if (event instanceof NavigationEnd) {
      this.showAnchor = event.url.includes('resume');
    }
  });
  this.showAnchor = this.route.children[0].routeConfig.path === 'resume';
}


ngOnDestroy(): void {
  if (this.routerChange) {
    this.routerChange.unsubscribe();
  }
}

 

posted on 2020-09-08 17:49  哈哈哈~_~  阅读(422)  评论(0)    收藏  举报