backbone.js - Unable to initialize new marionette router -
i trying create new app router within 'products' module shown below using marionette
@myapp.module "productsmodule", (productsmodule, app, backbone, marionette, $, _) -> class productsmodule.router extends marionette.approuter approutes: "products" : "listgoods" api = listgoods: -> console.log('list goods') app.addinitializer -> console.log('init app router') new productsmodule.router controller: api
the higher level app code follows
@myapp = (backbone, marionette) -> app = new marionette.application app.addregions headerregion: "#header-region" mainregion: "#main-region" footerregion: "#footer-region" app.on "initialize:after", (options) -> if backbone.history backbone.history.start root: '/admin/' app
however after trying run, approuter products module did not run i.e. console.log did not print out console.
am missing here?
update: adding more code show app started
<!doctype html> <html> <head> <title>admin</title> <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "admin" %> <%= csrf_meta_tags %> </head> <body> <div id="wrap"> <div id="header-region"></div> <div id="main-region" class="container"> <a href="#products">sss</a> </div> </div> <div id="footer-region"></div> //starting app here <%= javascript_tag %> $(function() { myapp.start(); }); <% end %> </body> </html>
move
console.log('init app router') new productsmodule.router controller: api
in
app.on("initialize:after", function(){/*place code here*/})
move
if backbone.history backbone.history.start root: '/admin/'
in
app.on("start", function(){/*place code here*/})
Comments
Post a Comment