Subrouting – a key to organizing complex apps
Subrouting is the idea of dividing an application's router into a number of module-specific routers. In a small- or medium-level application, you may never need something like this. However, for an application with multiple modules, a single router that handles all of the routes soon turns into a huge, unmanageable class. So, it is always preferable to split the main router into a set of module-specific routers.
Backbone.Subroute
(https://github.com/ModelN/backbone.subroute), a wonderful extension developed by Dave Cadwallader, provides the functionality that we are talking about. It lets the base router delegate all of the module-specific routes to the subrouter associated with that module. Let's understand the difference between a router and subrouter with the two examples that follow.
The all-in-one router
The following is the code for a single router that handles the routes of all the modules of an application:
var App = {}; var App.BaseRouter...