通过 RouterEvent 的 url 拿到的值不仅包含 path,还包含查询参数
async ngOnInit() {
this._router.events.subscribe(async (ev) => {
if (ev instanceof NavigationStart) {
debounceTime(50);
if (ev.url !== this._previousUrl) {
await this.setActiveTab(ev.url);
}
this._previousUrl = ev.url;
}
});
}
提了一个错误的问题,在 NavigationStart 的时候,ActivatedRoute 可能还没被更新
通知 deepseek 的思考过程知道的
NavigationStart
is an event from theRouter
service, which happens at the beginning of a navigation.- At the moment of
NavigationStart
, theActivatedRoute
might not yet be updated because the navigation hasn't completed.
自己处理一下 url
const path = ev.url.split('?')[0];