Skip to content

Instantly share code, notes, and snippets.

@iampeter
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iampeter/10981733 to your computer and use it in GitHub Desktop.
Save iampeter/10981733 to your computer and use it in GitHub Desktop.
Backbone Marionette - route handling inside modules
TodoModule = require './modules/todo/TodoModule'
class App extends Backbone.Marionette.Application
initialize: =>
@router = new Backbone.Marionette.AppRouter
@module('Todo', TodoModule)
@addInitializer( (options) =>
Backbone.history.start();
)
@start()
module.exports = new App()
module.exports = class TodoController
index: ->
# routed to home, handled in another object
TodoController = require './TodoController'
module.exports = class TodoModule extends BaseModule
initialize: ->
@startWithParent = true
@controller = new TodoController()
# use TodoModule as controller
@app.router.processAppRoutes @,
'home': 'index'
# OR
# use another object as controller
@app.router.processAppRoutes @controller,
'home': 'index'
index: ->
# routed to home
@iampeter
Copy link
Author

This way you can also distribute routes amongst Marionette modules, so that each module will add only the ones it needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment