Maybe I am missing something?
In an Angular 2 component, I am simply trying to get the full Activated Route.
I do not want to use location.href
.
My constructor is as follows:
constructor(private route: ActivatedRoute) {}
And in ngOnInit()
I tried finding the value here to no avail:
this.route.data.url
You don't need to use ActivatedRoute
for that, you need to use Router to query for the current URL in the form of string:
constructor(r: Router) {
console.log(r.url);
}
a simpler solution is to use LocationStrategy class from the @angular/common
for representing and reading route state directly from the browser's URL which is more convenient then this.router.url
when trying to get the router URL in form of a string.
import {LocationStrategy} from '@angular/common';
export class MyComponent implements OnInit {
constructor(private url:LocationStrategy) { }
ngOnInit() {
//this will log the current url
console.log(this.url.path());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With