Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);

This comment has been minimized.

Copy link

iongion commented Mar 14, 2013

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
You can’t perform that action at this time.