Search code examples
angularangular-router

Angular get route path - not resolved url


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'
    });
  }
}


Solution

  • 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,