Skip to content

Instantly share code, notes, and snippets.

@bjesuiter
Created November 24, 2020 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjesuiter/45293d6bf2f8fc6e502685659b00cd8a to your computer and use it in GitHub Desktop.
Save bjesuiter/45293d6bf2f8fc6e502685659b00cd8a to your computer and use it in GitHub Desktop.
How to get static data of activeRoute from route definition
class DemoComponent () {
constructor(
private router: Router,
) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => this.router.routerState.root),
map((route) => {
while (route.firstChild) route = route.firstChild;
return route;
}),
filter((route) => route.outlet === 'primary'),
mergeMap((route) => route.data),
takeUntil(this.onDestroy)
)
.subscribe((activeRouteData) => {
console.debug('ActiveRouteData: ', ActivatedRoute);
this.routeData = activeRouteData;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment