I need to get my current route without params in Angular 2, I found a way to get the current route with params as follows:
this.router.url
In my case I needed to compare the previous route and the new route, when changing only the :id on the url via router.navigate. Since I wanted the path without the different ids, I got the original path of the route:
/*
Routes = [
{ path: 'main/details/:id', component: DetailComponent }
]
previousRoute = '/main/details/1'
newRoute = '/main/details/2'
*/
this.routeSubscription = this.router.events.filter((event) => event instanceof ResolveStart)
.pairwise() // returns previous and current events
.subscribe((ev: [ResolveStart, ResolveStart]) => {
let sameRoute = ev[0].state.root.firstChild.routeConfig.path == ev[1].state.root.firstChild.routeConfig.path ?
ev[0].state.root.firstChild.routeConfig.path : undefiend;
if (sameRoute) {
// Same routes, probably different ids
console.log(sameRoute) // gives 'main/details/:id'
} else {
// Different routes
}
});