I have different routes(nested as well with children) which should when they are navigated to, change the document.title and the title of the navigation which displays the header.
As I learned I can set the document.title via the TitleService from Angular2.
Best way would be that I can either grab the title from the router data property or fetch this from the attached component.
I tried to listen to subscribe to router.events but the events are not delivering me the needed information.
Example code:
{path: '', redirectTo: '/dashboard', pathMatch: 'full'},
{
path: '',
component: IndexComponent
children: [
{ path: 'componentA', component: ComponentA, data: { title: 'ComponentA'} },
{ path: 'componentB', component: ComponentB },
{ path: 'componentC', loadChildren: '../cc.module#CModule'}
]
},
{ path: 'login', component: LoginComponent }
I added a plunker here: http://plnkr.co/edit/V35Njf49TY40Y8f1ChxR?p=preview
This plunker shows that there is different data set for 1) the parent route/component and 2) the child route/component.
How can I read the data in my parent component(or any other more central component/service) without implementing the activeRoute in each of my child components?