Issue #1793: Backbone.history.navigate should use this.getFragment instead of fragment to avoid routes getting triggered twice

This commit is contained in:
Brian Erickson
2012-11-01 22:41:47 -06:00
parent aeaf2ee9cf
commit 8decce8d7d
2 changed files with 56 additions and 1 deletions

View File

@@ -1167,7 +1167,7 @@
} else {
return this.location.assign(url);
}
if (options.trigger) this.loadUrl(fragment);
if (options.trigger) this.loadUrl(this.getFragment() || fragment);
},
// Update the hash location, either replacing the current entry, or adding

View File

@@ -492,4 +492,59 @@ $(document).ready(function() {
new Router;
});
test("#1793 Trailing spaces (pushState:false).", 1, function() {
var count = 0;
Backbone.history.stop();
// restart History with pushState:false
Backbone.history.start({
pushState: false
});
router.on("route:search", function(page) {
count = count + 1;
});
// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});
// manually fire checkUrl
Backbone.history.checkUrl();
equal(count, 1); // route event should be fired once
router.off("route:search"); //unbind events
});
test("#1793 Trailing spaces using browser location (pushState: false).", 1, function() {
var count = 0;
Backbone.history.stop();
Backbone.history.location = window.location; // Use browser location
// restart History with pushState:false
Backbone.history.start({
pushState: false
});
router.on("route:search", function(page) {
count = count + 1;
});
// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});
// manually fire checkUrl
Backbone.history.checkUrl();
equal(count, 1); // route event should be fired only once
router.off("route:search"); //unbind events
// restore location hash
window.location.hash = '';
});
});