I am wondering, if there is a way to know(using events) that the path is changed? I looked into both onpopstate & onhashchange. Both are not what I am looking for. My current requirements are, in a single page application:
Are these possible with native API's in the browser?
Listen for the load event, which fires when the page has finished loading:
function code(){
console.log('page loaded')
}
window.addEventListener('load', code)
To listen for pushState changes, you can override the default pushState behavior:
function trigger() {
console.log('state change')
}
var pushState = history.pushState;
history.pushState = function(state) {
if (typeof history.onpushstate == "function") {
history.onpushstate({state: state});
}
trigger()
return pushState.apply(history, arguments);
};
history.pushState(null, null, '/endpoint')