I encountered the same problem when rewriting tarheelreader.org. I use History.js and it works fine except for the upgrade issue in IE8. This hack works for me.
In my startup code, which only runs when the start page loads, I do:
var url = window.location.href; if (url.indexOf('#') > -1) {
where controller.stateChange() is the state change handler that I use for all history changes.
function stateChange() {
You can see all the code in main.js and controller.js at https://github.com/gbishop/TarHeelReaderTheme
Edit Further research led History.js to use the source URL instead of the root. This hack seems to handle this case.
function stateChange() { // handle changes in the URL var hist = History.getState(), url = hist.url, bar = window.location.href, context = hist.data; //console.log("State changed...", url, context); if (url != bar && bar.indexOf('#') > -1) { //console.log('bar = ', bar); // I think we only get here in IE8 // hack for hash mode urls var root = History.getRootUrl(), hashIndex = bar.indexOf('#'); if (root != bar.slice(0, hashIndex)) { // try to fix the url url = root + bar.slice(hashIndex); //console.log('new url =', url); window.location.href = url; } } renderUrl(url, context).then(function(title) { document.title = title; }); }
source share