Use JS to intercept pushState and replaceState events and pushstate events
History. pushState and history. replaceState can change the URL without refreshing the current page, but the content of the new page obtained through AJAX cannot be obtained.
Although various HTML5 documents say that the window. onpopstate event can intercept pushState messages, in actual tests, onpopstate has no function at all and cannot intercept pushState messages.
The code for correctly obtaining the pushState event was found after Google review.
Https://stackoverflow.com/a/25673911
// Add this:var _wr = function(type) { var orig = history[type]; return function() { var rv = orig.apply(this, arguments); var e = new Event(type); e.arguments = arguments; window.dispatchEvent(e); return rv; };};history.pushState = _wr('pushState');history.replaceState = _wr('replaceState');// Use it like this:window.addEventListener('pushState', function(e) { console.warn('THEY DID IT AGAIN!');});window.addEventListener('replaceState', function(e) { console.warn('THEY DID IT AGAIN!');});
This code overwrites the original function in history and then activates an event on its own.
This will solve the problem that pushState cannot activate the event.
Remember to put this code before loading the document.