Adds helper methods for Backbone.Marionette routes
Backbone.Marionette routes helper is the simple plugin which provides you methods with routes names for your application.
npm install marionette-routes-helper
Browser:
<script>...</script>
<script src="backbone.radio.js" type="text/javascript"></script>
<script src="backbone.marionette.js" type="text/javascript"></script>
<script src="marionette-routes-helper.js" type="text/javascript"></script>
Common JS:
var MarionetteRoutesHelper = require('marionette-routes-helper');
First you should initialize routes helper and pass to it the application root path.
MarionetteRoutesHelper.initialize({ root: '/' });
Next you should bind routes helper to your router. For example:
var Controller = Marionette.Object.extend({
method: function() { ... }
});
var Router = Marionette.AppRouter.extend({
appRoutes: {
"some/route": "method"
},
routes: {
"other/route/:id": "otherMethod"
},
controller: new Controller()
otherMethod: function() { ... }
});
MarionetteRoutesHelper.bind('myrouter', new Router());
Now routes methods are available for you. They are based on the following pattern routerName + RouterMethodName + "Path"
MarionetteRoutesHelper.myrouterMethodPath() // returns "some/route"
MarionetteRoutesHelper.myrouterOtherMethodPath(12) // returns "other/route/12"
{
root: '/' // application root path
}
Signature: .initialize(options)
initialize
sets base options
Signature: .initialized()
initialized
returns boolean which define routes helper state. It is sometimes useful to check whether your routes helper is already initialized.
if (!MarionetteRoutesHelper.initialized()) {
MarionetteRoutesHelper.initialize({ root: '' });
}
Signature: .bind(routerName, routerInstance)
bind
binds routes helper with router instance
Signature: .rootPath()
rootPath
returns the root path value which passed to it in initialize method
- The Marionette team for backbone.marionette.js
- Anton Gudkov for the idea and first draft