angular监听路由
// 声明订阅对象 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(); } }