How to detect url change in angular 2?

A route change can be detected using the router.events stream. ( How to detect a route change in Angular 2? ).

But I'm not sure how to detect a change in the browser URL.

+5
source share
1 answer

You can enter Location and subscribe to it

 constructor(location:Location) { location.subscribe(val => console.log(val); } 

As Harry said. It only notifies popState events (router or similar code changing the url)

+1
source

Source: https://habr.com/ru/post/1257827/


All Articles