3

Is there a way in Angular to get the actual route in the NavigationEnd event instead of just the resolved url which event.url returns? I don't what the resolved params.

export class AppComponent {
  constructor(private router: Router) {
    this.router.events
    .filter(event => event instanceof NavigationEnd)
    .subscribe((event: NavigationEnd) => {
        // how to get route path? Such as 'someList/:id'
    });
  }
}

2 Answers 2

3

I don't know if this is the best way but

this.router.routerState.snapshot.root.firstChild.routeConfig

will get you the route config for the current route which has the configured path,

Sign up to request clarification or add additional context in comments.

Comments

-1

You want something like this?

router.events.subscribe((event: Event) => {
  console.log(event);
  if (event instanceof NavigationEnd ) {
    this.currentUrl = event.url;
  }
});

5 Comments

No. That returns the resolved path, I want the path configured in routeconfig.
you can get that from router links?
How do I do that for the current path?
parse it and use this snippet as the anchor?
Do you have an example? I want to use it for tracking loaded routes, and not specific urls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.