How to get current route
Angular RC4:
You can import Router
from @angular/router
Then inject it:
constructor(private router: Router ) {}
Then call it's URL parameter:
console.log(this.router.url); // /routename
Inject Location
to your component and read location.path();
You need to add You need to add ROUTER_DIRECTIVES
somewhere so Angular can resolve Location
.import: [RouterModule]
to the module.
Update
In the V3 (RC.3) router you can inject ActivatedRoute
and access more details using its snapshot
property.
constructor(private route:ActivatedRoute) { console.log(route);}
or
constructor(private router:Router) { router.events.subscribe(...);}
See also Angular 2 router event listener