Untested, but according to Savkin's blog, put the following into the child to get the parent component's router parameters:
constructor(activatedRoute: ActivatedRoute, router: Router) {
const parentActivatedRoute = router.routerState.parent(activatedRoute);
this.id = parentActivatedRoute.params.map(routeParams => routeParams.id);
}
Comparing that code to what is in the Router guide, you will need to use the AsyncPipe with id
in your template, or you can use subscribe()
... or you can use snapshot
if you are sure the id value won't change:
this.id = parentActivatedRoute.snapshot.params['id'];
@Chris mentions in a comment below: this.router.routerState.pathFromRoot(this.route)
will return an array of activated routes down to the current route.
Then you can get the parameters of all of the activated routes.
Update: RouterState.pathFromRoot(someRoute)
is marked deprecated in master. In RC.5, use ActivatedRoute.pathFromRoot()
.