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.
You can use the activated route to get active URL. (<RouterStateSnapshot>activatedRoute['_routerState']). url , if you like to type it.
What is an activated route? The Angular Docs define the ActivatedRoute as. A service that is provided to each route component that contains route specific information such as route parameters, static data, resolve data, global query params and the global fragment.
This should help:
constructor(router: Router) { const url = router.url; }
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); }
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