Skip to content

Commit

Permalink
Fix #3078 - Router#execute receives route name.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Mar 23, 2014
1 parent 06f19f4 commit 6232078
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@
var router = this;
Backbone.history.route(route, function(fragment) {
var args = router._extractParameters(route, fragment);
if (router.execute(callback, args) !== false) {
if (router.execute(callback, args, name) !== false) {
router.trigger.apply(router, ['route:' + name].concat(args));
router.trigger('route', name, args);
Backbone.history.trigger('route', router, name, args);
Expand All @@ -1334,7 +1334,7 @@

// Execute a route handler with the provided parameters. This is an
// excellent place to do pre-route setup or post-route cleanup.
execute: function(callback, args) {
execute: function(callback, args, name) {
if (callback) callback.apply(this, args);
},

Expand Down
17 changes: 17 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,21 @@
Backbone.history.start({pushState: true});
});

test('Router#execute receives callback, args, name.', 3, function() {
location.replace('http://example.com#foo/123/bar?x=y');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {'foo/:id/bar': 'foo'},
foo: function(){},
execute: function(callback, args, name) {
strictEqual(callback, this.foo);
deepEqual(args, ['123', 'x=y']);
strictEqual(name, 'foo');
}
});
var router = new Router;
Backbone.history.start();
});

})();

0 comments on commit 6232078

Please sign in to comment.