Angular routes empty when checked


I am trying to get the current path of my Angular app. However, this is always returned empty.

      private route: ActivatedRoute
  ) {
    this.route.url.subscribe(segments => {
      var currentPath = segments[0].path;
      console.log("Current Route: ", currentPath);

No matter where I navigate, this is always empty:

enter image description here

What am I doing wrong here?


If you want to get current route url , you can use this code :

import { Router, ActivatedRoute } from '@angular/router';
    private router: Router,
    private activatedRoute: ActivatedRoute) {

If you want to get full url of web app . you should use this :


Answered By – Elvin Garibzade

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published