this.router.events.pipe(
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
map((event: NavigationEnd) => {
const arr = event.url.split('/');
return arr.length > 0 ? arr[1] : 'home';
}),
map(path => this.getSelectedIndex(path))
)
这样处理可以