我有一個根組件,並希望在其中的特殊部分內顯示路徑標題。
我可以檢測哪個路由在每個組件中處於活動狀態。
但是,我不知道如何在根組件內部完成它。在根組件中顯示路徑標題
這段代碼顯示在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