How to set up multiple routers and controllers in Backbone.Marionette

As my application grows, I feel the need for a more structured configuration of the router / controller. Marionette docs mention the following:

It is recommended to separate controller objects into smaller parts of related functions and have several routers / controllers, and not just one giant router and controller.

It would be great if there was an example of such a structure. Suppose I have a three-section website; People, media and articles. Ideally, I would like to have routers / controllers for each partition. Something like that:

App -- AppRouter -- AppController -- AppLayout -- PeopleRouter -- PeopleController -- PeopleLayout -- MediaRouter -- MediaController -- MediaLayout -- ArticleRouter -- ArticleController -- ArticleLayout 

It is very unclear to me how I can let the route ("/ people / detail / 1") be handled by a different router than the AppRouter. I seem to need to create modules for each section, but does this work well with RequireJS? It seems a little strange to use two different types of modules ...

It would be great if someone could point me in the right direction, all the examples that I found on the Internet are a bit confusing to me.

+7
marionette
source share
1 answer

Take a look at the app developed in my book on the puppet .

You can see 2 router files:

If you want to know more about the routing method used in the book, there is a free chapter in the sample section. Although he does not explain the various files of the router, he explains the idea of ​​the application state control branch from managing URLs; which may interest you.

Hope this helps!

+5
source share

All Articles