Universal URL change event listener in JavaScript

Viewed 1755

I've been looking for some way (without using a timer) to detect when the URL changes in any way. Here is what I've found so far:

window.addEventListener('popstate', function(){console.log('popstate changed')});

This code works just fine when the hash changes or a back/forward navigation is made. BUT, it doesn't catch when only the path changes. I tried it in the FireBase console where there is no hash in the URL and only the path changes when you navigate around. No dice, the popstate listener doesn't catch the change. Any advice?

0 Answers
Related