Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
reducing router code
MyRouter = Backbone.Router.extend({
routes: {
"": "mail",
"inbox": "mail",
"inbox/categories/:category": "mailCategory",
"inbox/:id": "mailMessage"
},
mail: function(){
BBCloneMail.MailApp.show();
},
mailCategory: function(category){
BBCloneMail.MailApp.showCategory(category);
},
mailMessage: function(messageId){
BBCloneMail.MailApp.showMessage(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){
Backbone.Router.prototype.constructor.call(this, options);
if (this.appRoutes){
this.processAppRoutes(options.app, 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);
}
}
});
@iongion

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.