关于angular 的路由title设置

在主模块下

  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: '测试标题' } },

上一篇:js字符串转换成数字与数字转换成字符串的实现方法


下一篇:spring boot + druid + 封装JdbcTemplate