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
and then split it:
this.router.url.split(';')[0]
But this looks as workaround, I think there should be better way?
For me, this is the cleanest solution I managed to do. I hope it helps
Native javascript will work to split the url into logical parts. Check out the "location" (or window.location) object. For example, using location at the url https://example.com/pathname1/pathname2?queryParam1=1&queryParam2=2 yields
this could help you:
Import Router:
Signature in the constructor:
Check the _router events property:
To get current route without query parameters, you can use below mentioned single line:
parseTree
fromRouter
helps fetching the segments without any knowledge about url structure.Start from here. If you have secondary outlets adjust as required.
I had a similar requirement, depending on which route I used to get the component I wanted different outcomes.
I found that
activatedRoute.routeConfig.path
was a great option and made it easy for me to see which route had been used.