I\'m able to get current route\'s path like: /about, /, /news with location.path(). But how can I get its alias instead (the \'as\' part in the definition of a route)?
For >= Angular2 RC.x (new router)
There are no aliases anymore in the new router.
You can get the relative route of the local component
routerOnActivate(curr:RouteSegment, prev?:RouteSegment, currTree?:RouteTree, prevTree?:RouteTree):void {
console.log(curr.stringifiedUrlSegments);
}
or the full path using
constructor(private router:Router) {}
routerOnActivate(curr:RouteSegment, prev?:RouteSegment, currTree?:RouteTree, prevTree?:RouteTree):void {
console.log(this.router.serializeUrl(tree));
}
or
constructor(router:Router, private location:Location) {
router.changes.subscribe(() => {
console.log(this.location.path());
});
}