Do not trigger router/history events if Router#execute returns false

This commit is contained in:
Maksim Horbachevsky
2014-02-22 17:46:02 +03:00
parent a717a71a0f
commit 520218769b
2 changed files with 18 additions and 1 deletions

View File

@@ -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);

View File

@@ -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');