Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
reducing router code
MyRouter = Backbone.Router.extend({
routes: {
"": "mail",
"inbox": "mail",
"inbox/categories/:category": "mailCategory",
"inbox/:id": "mailMessage"
mail: function(){;
mailCategory: function(category){
mailMessage: function(messageId){
MyRouter = BBCloneMail.AppRouter.extend({
routes: {
"": "showInbox",
"inbox": "showInbox",
"inbox/categories/:category": "showCategory",
"inbox/:id": "showMessage"
new MyRouter({
app: BBCloneMail.MailApp
Routing.AppRouter = Backbone.Router.extend({
constructor: function(options){, options);
if (this.appRoutes){
this.processAppRoutes(, this.appRoutes);
processAppRoutes: function(app, appRoutes){
var method, methodName;
var route, routesLength;
var routes = [];
var router = this;
for(route in appRoutes){
routes.unshift([route, appRoutes[route]]);
routesLength = routes.length;
for (var i = 0; i < routesLength; i++){
route = routes[i][0];
methodName = routes[i][1];
method = app[methodName];
router.route(route, methodName, method);

What are appRoutes, where and how do you define them ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.