Created
November 24, 2020 11:33
-
-
Save bjesuiter/45293d6bf2f8fc6e502685659b00cd8a to your computer and use it in GitHub Desktop.
How to get static data of activeRoute from route definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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