7

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.

Maxim Kuzmin
  • 2,574
  • 19
  • 24
bobek
  • 8,003
  • 8
  • 39
  • 75

1 Answers1

5

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;
    }
})
bobek
  • 8,003
  • 8
  • 39
  • 75