My problem is that I have a lang.component
loaded with <router-outlet>
. What I need is to access ActivatedRoute params in the root component which is app.component
but all route data there is empty. I am able to access route data from lang.component
normally by subscribing to params link to code that you can run: https://plnkr.co/edit/gTXPUb6TvatbMyOPPRKj
If you run the code and open your console you can see two logs. It shows you what the problem is.
Please help.
Thank you.
Since ActivatedRoute can be reused, ActivatedRouteSnapshot is an immutable object representing a particular version of ActivatedRoute . It exposes all the same properties as ActivatedRoute as plain values, while ActivatedRoute exposes them as observables.
ActivatedRoutelink. Provides access to information about a route associated with a component that is loaded in an outlet. Use to traverse the RouterState tree and extract information from nodes.
Instead of using ActivatedRoute use Router.
this.router.events.subscribe((event) => {
if(event instanceof NavigationEnd) {
var snapshot = this.router.routerState.firstChild(this.route).snapshot;
var params = snapshot.params;
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With