Angular Master (283 Qs)•Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)
How do you get the current route?
mid LevelMost AskedCode ExampleSignalsComponentsState Management
In Angular, there is an url property of router package to get the current route. You need to follow the below few steps,
- Import Router from @angular/router
js
import { Router } from '@angular/router';
- Inject router inside constructor
js
constructor(private router: Router ) {
}
- Access url parameter
js
console.log(this.router.url); // /routename