Angular2 get ActivatedRoute url

Robin Dijkhof picture Robin Dijkhof · Oct 20, 2016 · Viewed 49.7k times · Source

I want to get the url which comes from this:

this.router.navigate(./somepath, { relativeTo: this.route })

this.route is of the type ActivatedRoute.

I tried url: string = route.snapshot.url.join(''); but this gives an empty string.

Answer

viks picture viks · May 3, 2018

You can use the activated route to get active URL.

import { ActivatedRoute } from '@angular/router';
 constructor(
    private activatedRoute: ActivatedRoute) {
    console.log(activatedRoute.snapshot['_routerState'].url); 
}