1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > angular6 监听路由变化 获取路由名称

angular6 监听路由变化 获取路由名称

时间:2023-09-30 10:50:32

相关推荐

angular6 监听路由变化 获取路由名称

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

获取路由名称

constructor(private route: ActivatedRoute,private router: Router) {}this.route.url.subscribe(url => {this.activeRouteName = url[0].path;});// 或者this.router.url

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。