How to get current route How to get current route angular angular

How to get current route


The new V3 router has a url property.

this.router.url === '/login'


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 ROUTER_DIRECTIVES somewhere so Angular can resolve Location. You need to add 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