I am using the latest angular5 version. I have the following coded routes (note that fruits and veggies are NOT parameters:
/fruits/item
/veggies/basket
Note that fruits is a parent route, and I have multiple children routes in an array (item is just one of them). 'veggies' is also a parent route. 'basket' is one of the 'child routes' in an array under the veggies route.
How can I use "ActivatedRoute", though how do I get access to the first "fruits" or "veggies" segment of the route? I want to check it and log it out to the console.
Assume Activated route is already injected into the variable "route".
Looking for something like this pseudocode(if it is correct)
showRouteRoot() {
console.log(this.route.getFirstSegmentNameInRoute())
// expected output is fruits OR veggies.
// If this can't be done in one line of code,
// multiple lines is an acceptable answer
}
I've tried:
console.log(this.route.snapshot.url.split('/'));
This yields problems.
console.log(this.route.url)
This shows me some AnonymousSubject
console.log(this.route.parent.url)
This shows me a BehaviorSubject