2

In Angular (version >= 2), how to get the next route (URL) from router's navigation events?
For example, in the code below, how do I know the next route that Angular will navigate into?

    router.events.subscribe(routerEvent => {
      // How to get next route URL here ?
    })

router has type Router (imported from '@angular/router')

code đờ
  • 554
  • 1
  • 9
  • 19
  • `this.activatedRoute.firstChild` will give you the first next of url then go further and its .firstChild will give the next part – Beshambher Chaukhwan Jun 22 '21 at 04:16
  • Does this answer your question? [How to get current route](https://stackoverflow.com/questions/34597835/how-to-get-current-route) – Kinglish Jun 22 '21 at 04:20
  • @Kinglish No, the link is about getting current route, not the next route. For example, when routerEvent instanceof NavigationStart, I logged this.router.url but it prints the current route. – code đờ Jun 22 '21 at 04:37
  • 1
    I think the only solution to detect the destination is available by setting a guard for route changes, seems you can not detect destination by router events. – Arash Etemad Jun 22 '21 at 05:35

0 Answers0