Skip to content

Commit

Permalink
Merge pull request jashkenas#2393 from braddunbar/route-names
Browse files Browse the repository at this point in the history
Use empty route name for anonymous routes.
  • Loading branch information
jashkenas committed Mar 20, 2013
2 parents b0771d9 + 3d43134 commit 1c17c2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,11 @@
//
route: function(route, name, callback) {
if (!_.isRegExp(route)) route = this._routeToRegExp(route);
if (!callback) callback = _.isFunction(name) ? name : this[name];
if (_.isFunction(name)) {
callback = name;
name = '';
}
if (!callback) callback = this[name];
var router = this;
Backbone.history.route(route, function(fragment) {
var args = router._extractParameters(route, fragment);
Expand Down
5 changes: 4 additions & 1 deletion test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ $(document).ready(function() {
equal(router.anything, 'doesnt-match-a-route');
});

test("routes (function)", 2, function() {
test("routes (function)", 3, function() {
router.on('route', function(name) {
ok(name === '');
});
equal(ExternalObject.value, 'unset');
location.replace('http://example.com#function/set');
Backbone.history.checkUrl();
Expand Down

0 comments on commit 1c17c2e

Please sign in to comment.