I need to get the current URL present in the browser in my Angular 2 application.
In JavaScript normally we do it using the window object.
How can I do this
Import the ActivatedRoute, (and the rest of the Router stuff too, if you want)
import { ActivatedRoute, Params, Router, UrlSegment } from '@angular/router';
making sure it's injected into the constructor,
constructor(private route: ActivatedRoute) { ... }
and on ngOnInit you can use this.route
to inspect the URL. For instance, all the segments are in an array, which you can string together, as @ibgib suggested, like this:
let path = this.route.snapshot.url.join('/');
to give you something like "mars/moons/phobos".