'Angular Router.url not updating current path

My header component Router.url always returns a slash '/' rather than the navigated URL.

    currentLink?: string = ''

  constructor(private route: Router) { }

  ngOnInit(): void {
    this.getUrl()
  }

The app component where it's been used.

<app-header></app-header>

<router-outlet></router-outlet>
    
      getUrl() {
        this.currentLink = this.route.url
      }

I have tried AfterContentInit on child component still didn't work



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source