With the shift of application code to the client, we are continually seeing more single page web applications. But they come with a drawback. Since we are keeping the users on the same page, we are losing the natural ability of tracking steps through the URL changes.
Routers in Backbone are a solution to this problem. They allow the definition of routes inside your JavaScript code, giving back the feel of a web page to your rich web application.
Suppose that we want our application to support the URL routes to display different types of investment:
/investments/good
: To show only a list of the good investments/investments/bad
: To show only a list of the bad investments/investments/all
: To show a list of all the investments
Normally this would be handled on the server, but with Backbone, we can define how to handle these routes in JavaScript on the browser. There is one catch though, for this to work it needs to use hash the URL fragments (#/investments...