I'm unable to get a routing parameter from a child component in my Angular 6 application
I have the following routes set up in app-routing.module:
{
path: 'item/:id',
component: ItemLayoutComponent,
children: [
{ path: '', redirectTo: 'inbox', pathMatch: 'full' },
{ path: 'inbox', loadChildren: './feature/inbox/inbox.module#InboxModule' }
]
},
And then this in my inbox-routing-module.ts:
{
path: '',
component: InboxComponent,
children: [
{ path: '', redirectTo: 'messages', pathMatch: 'full' },
{
path: 'messages', component: MessagesComponent
},
]
}
This allows me to have a url that looks like this to get to my messages component:
item/5200/inbox/messages
My problem is that in my ItemLayoutComponent I can get the value of the id field (in this case 5200) with the following code:
this.route.snapshot.paramMap.get('id')
However I need the value of this ID in my MessagesComponent. Currently the same code gives me null.
parent?route.parent.snapshot.params['id']