Get group lookup value (**)

Is there a way to get (and display) the current route (**) for the user?

So, for example, one could display its value like this:

Sorry, but the page "/ WrongUrl" does not exist

Edit

To be clear, this question is about displaying a URL for UI purposes. Not how to create the correct route for a 404 error.

+3


source to share


2 answers


Angular has a location service that allows (by the way) to get the current path.



0


source


The current route is available as a property url

in Router

and ActivatedRoute

.

This is in line Router

, events

observable must be signed in order to keep track of the change:

router.events
.filter(e => e instanceof NavigationEnd)
.subscribe(({ url }) => {
  this.currentUrl = url;
});

      



This is an observation of parsed URL segments in ActivatedRoute

, it should be serialized to a string:

activatedRoute.url
.subscribe(urlSegments => {
  this.currentUrl = '/' + urlSegments.join('/');
});

      

0


source







All Articles