I found that most tutorials use one big router.
For example: https://github.com/thomasdavis/backboneboilerplate/blob/gh-pages/js/router.js
Wouldn’t it be better to separate the routes (controllers) into separate files?
If yes how can I combine this with requirejs?
I think this is a question of preference. If you’re doing a ginormous application with gazillion routes, then dividing your routers up is sensible. For small applications having just one big router is just fine.
If you decide to have multiple routers, make sure you don’t have conflicting routes, so there won’t be any unexpected behavior or errors.
So with requireJS: I think the best way would be to define each router in it’s own file like this
When you have all your desired routers set up you can bundle them up in the
app.jsI’ve never done this myself, but I don’t see why it wouldn’t work if you keep the routes from conflicting. Hopefully this clears stuff for you.