引入
import {ActivatedRoute,Router,NavigationEnd } from '@angular/router';//实例化Routerconstructor(private router:Router) {}
需要导入rxjs这个库才能使用filter方法
import {filter } from 'rxjs/operators';
ngAfterViewInit(){// 监听路由变化this.router.events.pipe(filter((event:any) => event instanceof NavigationEnd)).subscribe((event:NavigationEnd) => {// 加载数据方法(下面这里写自己的代码)console.log(event)this.type=this.route.snapshot.params.typethis.qingkong();//可以用封装好的函数,地址发生变化,重新加载页面数据});}