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

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: urlSegmenturlSegment[])=> 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

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

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
added 18 characters in body
Source Link
isherwood
  • 61.4k
  • 16
  • 122
  • 173

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){     router.url //Gives you the string path from root to current route. i.e /Root/CurrentRoute activatedRouterouter.url.value[0].path  //Gives you just the fragment of the current route. i.e. CurrentRoute activatedRoute.url.value[0].path // same as above activatedRoute.url.subscribe((url: urlSegment)=> console.log(url[0].path))  //The same as above activatedRoute.snapshot.url[0].path  //Save asthe above url fragment from the parent route i.e. Root //Since since the parent is an ActivatedRoute object, you can get the same using activatedRoute.parent.url.value[0].path // Gives you the url fragment from the parent route i.e. Root } 

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

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){   router.url //Gives you the string path from root to current route. i.e /Root/CurrentRoute activatedRoute.url.value[0].path //Gives you just the fragment of the current route. i.e. CurrentRoute activatedRoute.url.subscribe((url: urlSegment)=> console.log(url[0].path)) //The same as above activatedRoute.snapshot.url[0].path //Save as above  //Since the parent is an ActivatedRoute object, you can get the same using activatedRoute.parent.url.value[0].path // Gives you the url fragment from the parent route i.e. Root } 

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

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 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
Source Link
n4nd0_o
  • 3k
  • 1
  • 17
  • 9

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){ router.url //Gives you the string path from root to current route. i.e /Root/CurrentRoute activatedRoute.url.value[0].path //Gives you just the fragment of the current route. i.e. CurrentRoute activatedRoute.url.subscribe((url: urlSegment)=> console.log(url[0].path)) //The same as above activatedRoute.snapshot.url[0].path //Save as above //Since the parent is an ActivatedRoute object, you can get the same using activatedRoute.parent.url.value[0].path // Gives you the url fragment from the parent route i.e. Root } 

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