Chapter 5. Routing Best Practices and Subrouting
A router is one of the most useful objects in Backbone; it is mainly used to route application URLs using hash fragments or standard URLs. In the earlier versions of Backbone, Backbone.Controller
was used to take care of routing as well as default controller tasks, instead of Backbone.Router
. Later, it was changed to Backbone.Router
, because the router is meant to only handle routing client side pages and connect them to events and actions via URLs, while the functional logic must be taken care of by the presenters (that is, Backbone views). The concept of a router is pretty straightforward—it matches the method name to the URL fragment and calls the method. The method then takes care of the events and actions as required.
In this chapter, we will learn about some best practices, such as how to organize routers for medium- and large-scale applications, and which types of tasks should be handled by a router. The main topics to be covered are...