I have a main component that has a router-outlet in it. In the component that is loaded in the router-outlet I grab the url parameter like this:
ngOnInit():
I was having a very similar problem with this mainly due to my misunderstanding of how routes actually worked. I thought I could just go up the chain of path parameters and each one would be a parent/child relationship. However, if a route has more than one element to the path, (e.g. /dashboard
and profile/:user_id
) it will depend on how you set up the routes in your routing module(s).
To explain a different way that made it click for me:
// If I am trying to access ActivatedRoute from the CheckMobileComponent (say
// through a `router-outlet`), I could get it through something like
// `this._route.firstChild`
{ path: '', component: CheckMobileComponent, children: [
// If I want to get things from the '' context in MobileReportComponent, it
// would be through something like `this._route.parent`
{ path: 'report', component: MobileReportComponent }
]
}