mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Issue #1793: Backbone.history.navigate should use this.getFragment instead of fragment to avoid routes getting triggered twice
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = '';
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user