Created
May 9, 2014 09:26
-
-
Save mygoare/0561b64b46a8b63ddd18 to your computer and use it in GitHub Desktop.
Backbone router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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