How to configure Routes in Marionette.js ?

devquora
devquora

Posted On: Feb 22, 2018

 

The routes are configured in the appRoutes. The definition of the route is passed to Backbone’s standard routing handlers. You have to provide a callback method that exists on the controller instead of a callback function that exists on the router.

Example of configuration routes with appRoute

 var MyRouter = Backbone.Marionette.AppRouter.extend({
  // "someMethod" must exist at controller.someMethod
  appRoutes: {
    "some/route": "someMethod"
  },

  /* standard routes are mixed with appRoutes/Controllers above */
  routes : {
    "some/otherRoute" : "someOtherMethod"
  },
});

The routes can also be configured in the constructor.

Example

var MyRouter = new Marionette.AppRouter({
  controller: myController,
  appRoutes: {
    "foo": "doFoo",
    "bar/:id": "doBar"
  }
});

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Marionette js Interview Questions

    What is Marionette.js ?

    Marionette.js is a composite application library for the Backbone.js. It simplifies the construction of the large-scale JavaScript applications. It is nothing but a collection of the common design and...

    Marionette js Interview Questions

    List some features of Marionette.js ?

    Features of Marionette.jsIt is scalable as the applications built-in modules with event-driven architecture. It is easily modifiable. It works with the specific need of your application. It has ...

    Marionette js Interview Questions

    What is current stable version of Marionette.js ?

    v4.1.2 is the current stable version of MarionetteJS....