I am using a class base component and I do not want to use a functional component
component1.js
// web default watch id is 1 e.g /watch?id=1
const newURL = "/watch?id=2";
window.history.pushState(null, null, newURL);
I tried the following code but it's not working :
component2.js
window.onpopstate = () => {
console.log("Change in parameter detected");
};
I also tried "onhashchange" but it works only when hash changes in URL bar :
window.onhashchange= () => {
console.log("Change in parameter detected");
};