title: Angular - How to get current url in app component
body: <p>I am trying to get current url of application in <code>AppComponent</code> but it always returns the root path <code>/</code>. Example, if I visit <code>/users</code> in new tab, the expected result should be <code>/users</code>, but when I check in the console, it shows
  <code>/</code>.</p>
  
  <p>However, it works when I do the same in a child component. Below are my code:</p>
  
  <pre><code>import {Component} from '@angular/core'
  import {ActivatedRoute, Router} from '@angular/router'
  
  @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['app.component.scss'],
  })
  
  export class AppComponent {
      constructor(router: Router) {    
          console.log(this.router.url) // return '/'    
      }
  }
  </code></pre>
  
  <p>How is that possible?</p>