How do you get the current route?

In Angular, there is an url property of router package to get the current route. You need to follow the below few steps,

  1. Import Router from @angular/router
import { Router } from '@angular/router';
  1. Inject router inside constructor
constructor(private router: Router ) {
  1. Access url parameter
console.log(this.router.url); // /routename

April 27, 2022