mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Do not trigger router/history events if Router#execute returns false
This commit is contained in:
@@ -1251,7 +1251,7 @@
|
||||
var router = this;
|
||||
Backbone.history.route(route, function(fragment) {
|
||||
var args = router._extractParameters(route, fragment);
|
||||
router.execute(callback, args);
|
||||
if (router.execute(callback, args) === false) return;
|
||||
router.trigger.apply(router, ['route:' + name].concat(args));
|
||||
router.trigger('route', name, args);
|
||||
Backbone.history.trigger('route', router, name, args);
|
||||
|
||||
@@ -331,6 +331,23 @@
|
||||
Backbone.history.checkUrl();
|
||||
});
|
||||
|
||||
test("does not fire event when route callback explicitly returned false", 1, function() {
|
||||
var router = new Router({});
|
||||
var passed = true;
|
||||
|
||||
router.execute = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
router.on('route', function() {
|
||||
passed = false;
|
||||
});
|
||||
|
||||
location.replace('http://example.com#route-event/x');
|
||||
Backbone.history.checkUrl();
|
||||
ok(passed);
|
||||
});
|
||||
|
||||
test("#933, #908 - leading slash", 2, function() {
|
||||
location.replace('http://example.com/root/foo');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user