Multiple routers vs single router in BackboneJs

i wrote an app (still writing) with multiple routers in it.
however it is not like you think, it is more module based and not a router per view or anything like that.

for example,
say i got two big modules in my app, 1 handling all books, and 1 for the users.
books have multiple views (as do users), a list view, detail view, edit view, etc etc…
so each module has its own router,
which stands for its own set of urls:

// user module...
var userRouter = Backbone.Router.extend({
    routes: {
        "users": "loadUsers",
        "users/add": "addUser",
        "user/:id": "loadUser",
        "user/:id/edit": "editUser"
    }

// ... rest dropped to save the trees (you never know if someone prints this out)
});


// book module
var bookRouter = Backbone.Router.extend({
    routes: {
        "books": "loadBooks",
        "books/add": "addBook",
        "book/:name": "loadBook",
        "book/:name/edit": "editBook"
    }

// ... rest dropped to save the trees (you never know if someone prints this out)
});

so, it is not like my two routers are competing for the same route, they each handle their own set of routes.

edit
now that I had more info via Elf Sternberg, I know it isn’t possible by default to have multiple routers match on the same route. without a workaround like overriding the backbone history or using namespaces in routes and regexes to match these routes.
more info here: multiple matching routes
thanks Elf Sternberg for the link.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)