私はルートコンポーネントを持っていて、その中に特別なセクション内にルートタイトルを表示したい。
すべてのコンポーネントでどのルートがアクティブであるかを検出できます。
しかし、私はルートコンポーネントの内部でそれを行う方法を知らない。ルートコンポーネント内にルート名を表示
このコードはChildComponent1のタイトル罰金を示しています
route:ActivatedRoute
ngOnInit() {
this.route.data.subscribe(
data => console.log(data)
)
}
は、どのように私は、現在のroute`sのタイトルが何であるかを検出し、ルートコンポーネントの内側にそれを表示することができますか?
export const routes: Routes = [
{path: '', component: Component1, canActivate: [NonAuthGuard]},
{
path: 'root', component: rootcomponent, canActivate: [AuthGuard], children: [
{
path: 'Child1',
component: ChildComponent1,
data: {
title: 'Child1'
},
canActivate: [AuthGuard],
canDeactivate: [CanDeactivateGuard]
},
{
path: 'Child2',
component: ChildComponent2,
data: {
title: 'Child2'
},
canActivate: [AuthGuard],
canDeactivate: [CanDeactivateGuard]
},
]}
UPD:ここで答えが見つかりましたhttp://stackoverflow.com/questions/38644314/changing-the-page-title-using-the-angular-2-new-router – norweny