Issue
When using Router ( this.router.url
) I am get the string /MyRouterName?type=abc
, sometime /MyRouterName
if not have parameter
Can I only get the path /MyRouterName
(for all cases) from the full url?
Solution
You can use the activated route component's snapshot to get this url.
import { Router, ActivatedRoute } from '@angular/router';
constructor(
private router: Router,
private activatedRoute: ActivatedRoute) {
console.log("routes");
console.log(activatedRoute.snapshot.url); // array of states
console.log(activatedRoute.snapshot.url[0].path);
}
Link to original SO answer by Jose G Varanam How to get current route
Answered By - user5049376
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.