Given a route config
{
path: \'/root/:rootId\',
children: [{
path: \'/child1/:child1Id\',
children: [{
path: \'/child2/:child2
constructor(private route: ActivatedRoute) {}
data$ = of(this.route).pipe(
expand(route => of(route['parent'])),
takeWhile(route => !!route['parent']),
pluck('snapshot', 'data'),
reduce(merge));
Explanation:
Calling expand here creates an observable for each route in the parent chain. Takewhile is used so that it stops recursing when route['parent'] returns null, or at the root route.
Then, for all of those routes in the observable, pluck will map each to it's 'snapshot.data' property.
Finally, reduce is being fed the merge function from lodash to combine all the data objects into one object. This stream aggregates all the data from the current route through the parent routes