Skip to content

Instantly share code, notes, and snippets.

@mygoare
Created May 9, 2014 09:26
Show Gist options
  • Save mygoare/0561b64b46a8b63ddd18 to your computer and use it in GitHub Desktop.
Save mygoare/0561b64b46a8b63ddd18 to your computer and use it in GitHub Desktop.
Backbone router
var WorkspaceRouter = Backbone.Router.extend({
routes: {
"help": "help", // #help
"search/:query": "search", // #search/kiwis
"search/:query/p:page": "search" // #search/kiwis/p7
},
help : function () { },
search : function () { }
});
var App = {
help: function() { console.log("help"); },
search: function(query, page) { console.log("search", query, page); }
};
$(document).ready(
function () {
var router = new WorkspaceRouter();
Backbone.history.start();
router.on("route:help", App.help);
router.on("route:search", App.search);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment