backbone.js - Marionette js routing - What am I doing wrong here? I'm getting error that route actions are undefined? -
just want basic routing , going. having seen number of examples thought code below should work, when run error "unable property 'dochat' of undefined or null reference". have initialization sequence wrong?
require(["marionette", "jquery.bootstrap", "jqueryui"], function (marionette) { window.app = new marionette.application(); app.start(); app.addregions({ //add regions here }); //set routing var approuter = marionette.approuter.extend({ approutes: { "": "dodefault", "chat": "dochat" }, dodefault: function () { alert("doing default...") }, dochat: function () { alert("doing chat...") } }); var router = new approuter(); //history if (backbone.history) { backbone.history.start(); } })
the approuter allows 2 types of routes, standard backbone routes defined in routes
property , routes call functions in object defined in approutes
property.
so above code working, can 1 of 2 things. quickest change approutes
property routes
normal backbone routing. second option create object , pass approuter
controller during instantiation:
var mycontroller = { dodefault: function () { alert("doing default...") }, dochat: function () { alert("doing chat...") } } var router = new approuter({ controller: mycontroller });
this detailed in approuter documentation.
Comments
Post a Comment