Skip to content

Instantly share code, notes, and snippets.

@ianstormtaylor
Created April 28, 2012 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianstormtaylor/2519665 to your computer and use it in GitHub Desktop.
Save ianstormtaylor/2519665 to your computer and use it in GitHub Desktop.
Enhanced Backbone.Router route function to handle trailing slashes and query strings.
// Enhanced route function that automatically binds variant routes.
route : function (route, name, callback) {
var variants = [
route,
route + '/',
route + '?:querystring',
route + '/?:querystring'
];
// Bind a route for each of the variants.
for (var i = 0, rut; rut = variants[i]; i++) {
Backbone.Router.prototype.route.call(this, rut, name, callback);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment