My route management is explained in a free preview of my book Marionette ( http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf )
Basically, my opinion (others do not necessarily share it) is that the routing of the backbone should be used to configure the state of the application when the user "enters" the application through the URL. In other words, it will analyze the parameters and trigger the correct controller actions.
But once this initial state is configured, the routing code should no longer run even when the user navigates through the application.
Here is an example:
- The user enters "contacts / 2 / editing". The main routing code retrieves argument
2 and invokes the action of the edit controller with this id parameter (which retrieves this contact, displays the corresponding views, etc.). In other words, the state of the source application is configured. - The user clicks the "show all contacts" link leading to the URL of the contacts. Here, I believe that this modification should be handled through Marionette events (i.e. indicate that the user wants to see all contacts). In the end, we know what the user wants to do, and which fragment of the URL should be displayed. In other words, there is no reason to include a routing code.
Please note that this is my opinion, and other developers simply pass trigger: true when the user clicks the link. But, as I explain in the excerpt from the book above, this leads to the fact that developers create "stateless applications in javascript" (for example, they pass a lot of parameters to the URL, although they must be stored in the state of the application). For all reasons, there is a reason that the Backbone navigate method has trigger: false .
Derick Bailey (creator of Marionette) also discussed this issue here: http://lostechies.com/derickbailey/2011/08/03/stop-using-backbone-as-if-it-were-a-stateless-web-server/
source share