bobek bobek - 1 year ago 57
AngularJS Question

Accessing Route data in root component, route data is empty

My problem is that I have a

loaded with
. What I need is to access ActivatedRoute params in the root component which is
but all route data there is empty. I am able to access route data from
normally by subscribing to params link to code that you can run:

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.

Answer Source

Instead of using ActivatedRoute use Router. => {
    if(event instanceof NavigationEnd) {
        var snapshot = this.router.routerState.firstChild(this.route).snapshot;

        var params = snapshot.params;