Last active
August 29, 2015 13:59
-
-
Save iampeter/10981733 to your computer and use it in GitHub Desktop.
Backbone Marionette - route handling inside modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = class TodoController | |
index: -> | |
# routed to home, handled in another object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This way you can also distribute routes amongst Marionette modules, so that each module will add only the ones it needs.