Skip to content

Commit

Permalink
Merge pull request #1696 from braddunbar/pushstate-transition
Browse files Browse the repository at this point in the history
Fix #1695 - Ignore location.search during pushState transition.
  • Loading branch information
jashkenas committed Oct 2, 2012
2 parents 84039f3 + 3f530c2 commit 64e2d0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@
// opened by a non-pushState browser.
this.fragment = fragment;
var loc = this.location;
var atRoot = (loc.pathname.replace(/[^\/]$/, '$&/') === this.root) && !loc.search;
var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;

// If we've started off with a route from a `pushState`-enabled browser,
// but we're currently in a browser that doesn't support it...
Expand All @@ -1073,7 +1073,7 @@
// in a browser where it could be `pushState`-based instead...
} else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
this.fragment = this.getHash().replace(routeStripper, '');
this.history.replaceState({}, document.title, this.root + this.fragment);
this.history.replaceState({}, document.title, this.root + this.fragment + loc.search);
}

if (!this.options.silent) return this.loadUrl();
Expand Down
18 changes: 18 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,22 @@ $(document).ready(function() {
});
});

test("#1695 - hashChange to pushState with search.", 1, function() {
Backbone.history.stop();
location.replace('http://example.com/root?a=b#x/y');
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: function(){},
replaceState: function(state, title, url){
strictEqual(url, '/root/x/y?a=b');
}
}
});
Backbone.history.start({
root: 'root',
pushState: true
});
});

});

0 comments on commit 64e2d0a

Please sign in to comment.