javascript - Marionettejs Routes -
i'm new marionette , can't routes work.
i'm using marionette's 2.4.1 version, , trying simplest way possible it'll work.
this code works old version of marionette, v1.0.2, included in 1 of yeoman's generator. know there's huge gap between 2 versoins every post, blog, official documentation , books written framework code stays same.
there no errors in console, 'home' method won't start.
am missing here?
application.js (application body):
define(['backbone', 'marionette'], function (backbone, marionette) { 'use strict'; var app = new marionette.application(); app.router = marionette.approuter.extend({ approutes: { "home": "home" } }); var mycontroller = { "home": function() { console.log("this thing won't work."); } }; /* add initializers here */ app.addinitializer(function () { console.log('app initialized'); new app.router({ controller: mycontroller }); }); app.on("initialize:after", function () { if (backbone.history) { backbone.history.start(); } }); return app; });
main.js (starts our app defined in application.js):
require(['marionette', 'application'], function ( marionette, app ) { 'use strict'; app.start(); });
config.js (config require.js)
require.config({ baseurl: "/scripts", /* starting point application */ deps: ['marionette', 'main'], shim: { backbone: { deps: [ 'underscore', 'jquery' ], exports: 'backbone' }, marionette: { deps: ['backbone'], exports: 'marionette' } }, paths: { backbone: '../bower_components/backbone/backbone', jquery: '../bower_components/jquery/dist/jquery', underscore: '../bower_components/underscore/underscore', /* alias marionette libs */ 'marionette': '../bower_components/marionette/lib/core/backbone.marionette', 'backbone.wreqr': '../bower_components/backbone.wreqr/lib/backbone.wreqr', 'backbone.babysitter': '../bower_components/backbone.babysitter/lib/backbone.babysitter' } });
it looks you're missing reference router's controller.
try updating router include reference mycontroller:
app.router = marionette.approuter.extend({ controller: mycontroller, approutes: { "home": "home" } });
see approuter docs more infomation: http://marionettejs.com/docs/v2.4.1/marionette.approuter.html
Comments
Post a Comment