mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 22:08:04 -05:00
Better hash-to-pushState upgrades, via replaceState.
This commit is contained in:
12
backbone.js
12
backbone.js
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user