Better hash-to-pushState upgrades, via replaceState.

This commit is contained in:
Jeremy Ashkenas
2011-07-01 17:08:59 -04:00
parent dc84cc6ac5
commit c39ddd0c16

View File

@@ -801,16 +801,16 @@
// opened by a non-pushState browser.
this.fragment = fragment;
historyStarted = true;
var started = this.loadUrl() || this.loadUrl(window.location.hash);
var atRoot = window.location.pathname == this.options.root;
var loc = window.location;
var atRoot = loc.pathname == this.options.root;
if (this._wantsPushState && !this._hasPushState && !atRoot) {
this.fragment = this.getFragment(null, true);
window.location = this.options.root + '#' + this.fragment;
} else if (this._wantsPushState && this._hasPushState && atRoot && window.location.hash) {
this.navigate(window.location.hash);
} else {
return started;
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
this.fragment = loc.hash.replace(hashStrip, '');
window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
}
return this.loadUrl();
},
// Add a route to be tested when the fragment changes. Routes added later may