Skip to main content
3 of 3
it is 'url: urlSegment[]' of type 'Array<urlSegment>' not type 'urlSegment'

For those who are still looking for this. On Angular 2.x there are a few ways of doing it.

constructor(private router: Router, private activatedRoute: ActivatedRoute){ // string path from root to current route. i.e /Root/CurrentRoute router.url // just the fragment of the current route. i.e. CurrentRoute activatedRoute.url.value[0].path // same as above with urlSegment[] activatedRoute.url.subscribe((url: urlSegment[])=> console.log(url[0].path)) // same as above activatedRoute.snapshot.url[0].path // the url fragment from the parent route i.e. Root // since the parent is an ActivatedRoute object, you can get the same using activatedRoute.parent.url.value[0].path } 

References:

  1. https://angular.io/docs/ts/latest/api/router/index/ActivatedRoute-interface.html
  2. https://angular.io/docs/ts/latest/api/router/index/Router-class.html
  3. https://angular.io/docs/ts/latest/guide/router.html
n4nd0_o
  • 3k
  • 1
  • 17
  • 9