Consider the following structure:
const paths: Routes = [
{
path: 'matches',
children: [
{ path: '', pathMatch: 'full', redirectTo: 'fixtures' },
{ path: 'fixtures', component: FixturesComponent },
{ path: 'competitions', component: CompetitionsPageComponent },
{
path: ':page',
component: PageComponent,
children: [
{
path: ':team',
component: TeamComponent
children: [
{
path: ':season',
component: SeasonComponent,
children: [
]
}
]
}
]
}
]
}
];
Depending on in which component you inject ActivatedRoute
, you will be able to access different route parameters. For example
If you inject ActivatedRoute
in SeasonComponent
and do the following:
this._route.params.subscribe(p => console.log(JSON.stringify(p)));
You will see an object made of page,team and season properties.
If you do the same for PageComponent
, you will get an object made of only one property, page. If u get the point, if you inject ActivatedRoute
in the TeamComponent
, parameters would have only 2 properties.
The fact that you listen to the Router events and then read the properties in the ActivatedRoute
instance dont make a difference, because the injected instance of the ActivatedRoute
class contains only the parameters that where present in the route at the moment that the component, in which the instance is being injected, was generated.
So basically, at least with this approach, is not possible to access from a component at a certain level in the component hierarchy to route parameters further down in it.
Hope it helps!