javascript - Mithril: defer route configuration until DOM is ready -


my app has div in view, used mounting point pages of app.

app.view = function(ctrl) {     return [         appheader.view(),         appnav.view(),         m("#page")     ]; }; 

the following doesn't seem work:

m.mount(document.getelementbyid("app"), app);  m.route.mode = "hash"; m.route(document.getelementbyid("page"), "", {     "select_company": admin.selectcompany }); 

it works if include <div id="page"></div> directly in app.html. how solve above issue, without writing html directly?

i told @arthurclemens , @barneycarroll through gitter chat using m.mount() , m.route() both in 1 application not recommended approach. 1 solution provided @barneycarroll use m.route(), , use function return page view along other common parts of application below (jsbin here):

var header = {   view : function(){     return m( "h1", "this persistent site header" )   } }  var nav = {   controller : function(){     this.links = [       [ "/", "home" ],       [ "/select_company", "companies" ]     ]   },   view : function( ctrl ){     return m( "ul",        ctrl.links.map( function( link ){     return m( "li",        m( "a", {         config : m.route,         href   : link[ 0 ]       }, link[ 1 ] )     )       } )     )   } }  function furnish( component ){   return {     view : function(){       return [     header,     nav,     component       ]     }   } }  var home = {   view : function(){     return m( "h2", "welcome!" )   } }  var selectcompany = {   view : function(){     return m( "h2", "please select company" )   } }  m.route.mode = "hash"; m.route( document.body, "/", {     "/"              : furnish( home ),     "/select_company": furnish( selectcompany ) } ); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -