From c39ddd0c16ef1c7b372dc37cdc7d283d686e01aa Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 1 Jul 2011 17:08:59 -0400 Subject: [PATCH] Better hash-to-pushState upgrades, via replaceState. --- backbone.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backbone.js b/backbone.js index cce2dcce..5dc7042c 100644 --- a/backbone.js +++ b/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