在主模块下

  constructor(
    private router: Router,
    private activatedRoute: ActivatedRoute,
  ) {}
    this.router.events
      .filter(event => event instanceof NavigationEnd)
      .map(() => this.activatedRoute)
      .map(route => {
        while (route.firstChild) route = route.firstChild;
        return route;
      })
      .filter(route => route.outlet === 'primary')
      .mergeMap(route => route.data)
      .subscribe((event) => this.titleService.setTitle(event['title']));

路由设置

 { path: 'test', component: TestComponent, data: { title: '测试标题' } },

 posted on 2018-04-03 11:54  落逸  阅读(309)  评论(0编辑  收藏  举报