0

您好,我有 2 个路由模块 app.routing 和 account.routing 我正在尝试从路由中获取标题,但不适用于 account.routing 下的路由

  { path: 'mypath', loadChildren: () => import('./sap/sap.module').then(mod => mod.SApModule), data: { breadcrumb: 'SaP', title: 'TITLEs' } },

  const appTitle = this.titleService.getTitle();
  this.router
    .events.pipe(
      filter(event => event instanceof NavigationEnd),
      map(() => {
        const child = this.activatedRoute.firstChild;
        if (child.snapshot.data['title']) {
          return child.snapshot.data['title'];
        }
        return appTitle;
      })
    ).subscribe((ttl: string) => {
      this.titleService.setTitle(ttl);
    });
4

0 回答 0