2

I am new to Backbone Marionette JS and wondering how its routing works. Is any one can explain me or point me to the right direction to look at it.

Thanks in advance.

modon
  • 241
  • 3
  • 7
  • 14

4 Answers4

2

You should have a look at

https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.approuter.md

  • And other Marionette Samples

https://github.com/davidsulc/marionette-gentle-introduction

  • This is a great place to start with. You will get to know how things work in Marionette and how different is it with Backbone Code Style.
1

Marionette Router extends the Backbone Router object. It is an object that registers URL's to methods (functions). It means that whenever you navigate to a new URL your client will do a GET request to the server (which will download the html files and css, js imported inside). Then, the method corresponding to the route will be evaluated.

There is a standard used for browsers. Whatever in front of the # is requested to the server, and whatever is after will go inside your Routers.

You only need to instantiate a Router in order for the routes to work. I think it registers to a global variable in Backbone. After you activate the history in Backbone, you can use those routes.

AlexandruB
  • 678
  • 3
  • 15
1

I was looking for something like this, hope this will help someone else. The example is used from Davis Sulc's book Gentle Introduction to Marionette.

ContactManager.module("ContactsApp",function(ContactsApp,ContactManager,Backbone,Marionette_){
ContactsApp.Router = Marionette.AppRouter.extend({
appRoutes: {
  "contacts": "listContacts"
});
varAPI={
   listContacts: function(){
    console.log("route to list contacts was triggered");
   }
};
ContactManager.addInitializer(function(){ new ContactsApp.Router({
   controller: API
 });
 }); 
});
modon
  • 241
  • 3
  • 7
  • 14
0

Davis Sulc's book Gentle Introduction to Marionette is a good starting place. Understanding the concept of Marionette.Controller and Marionette.Module will help in splitting up routers for better maintainability.

Cheng Ping Onn
  • 687
  • 1
  • 8
  • 17