因为你用的是rxjs6.0版本所以代码要稍微变换一下,引入的头文件是import {filter} from 'rxjs/operators';
构造函数的代码是
constructor(public router: Router) {
this.router.events.pipe(
filter((event: Event) => event instanceof NavigationEnd)
).subscribe((event: NavigationEnd) => {
if (event.url === '/dashboard') {
this.pageTitle = '这里是首页';
this.pageDesc = '';
} else if (event.url.startsWith('/stock')) {
this.pageTitle = '股票信息管理';
this.pageDesc = '进行股票信息基本增删改查';
}
});
}