0

In SPA, Everything gets routed using routing mechanism. I just want to listen to an event whenever any part of url changes (Not just the hash but any change )

Following is example of SPA,

https://www.google.in/
https://www.google.in/category 

Now whenever url changes from https://cherrycrumble.com/ to https://cherrycrumble.com/en/girls-dresses.html, I want to capture that event.

I tried,

window.addEventListener("hashchange",function(event){
    console.log(this); // this gets fired only when hash changes
});
Mohit Mutha
  • 2,921
  • 14
  • 25
  • It is only possible if the url change was triggered by the user (e.g. going back with `onpopstate`). You cannot detect programmatical changes or page reloads – Jonas Wilms Nov 18 '19 at 09:55

1 Answers1

0

Did you try popstate ?

window.addEventListener('popstate', function(e){console.log('url changed')});
METALHEAD
  • 2,734
  • 3
  • 22
  • 37