Skip to content

Instantly share code, notes, and snippets.

@McKabue
Created May 22, 2018 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McKabue/724f347af51feaa9a9454a89eb7f5ad8 to your computer and use it in GitHub Desktop.
Save McKabue/724f347af51feaa9a9454a89eb7f5ad8 to your computer and use it in GitHub Desktop.
This little gem ensures a consistent update of the browser history (both url and title) in an Single Page Application in a conventional manner
if ('history' in window) {
window.history.__pushState = window.history.pushState;
window.history.pushState = function (_data, _title, _url) {
window.history.__pushState(null, null, _url);
window.document.title = _title;
};
window.history.__replaceState = window.history.replaceState;
window.history.replaceState = function (_data, _title, _url) {
window.history.__replaceState(null, null, _url);
window.document.title = _title;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment