The current docs only talk about getting route params, not the actual route segments.
For example, if i want to find the parent of current route, how is that possible?
There are many ways by which you can get a current Route or URL in Angular. You can use the router service, location service or window object to get the path. You can also listen to changes to URL using the router event or URL change event of the location service.
Use the useLocation() hook to get the current route with React Router, e.g. const location = useLocation() . The hook returns the current location object. For example, you can access the pathname as location. pathname .
When a button in the bottom bar is clicked, its current route path (/a/b/c) is saved and previously saved route is restored according to the button click. Conceptually user will think each button as a workspace and its state is never get lost (including back stack).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With