简体   繁体   中英

Materialize sidebar navigation stops working after installation of iron:router in meteor app

I attempting to build a Meteor app using Materialise ( http://materializecss.com ) as styling framework.

I began by replacing the default meteor app with the materialise starter template.

When the browser window is shrunk sufficiently the navbar items shrink to the 'hamburger' icon but when you click on it the items appear.

Critical to making this work seemed to be installation of this javascript code

 if (Meteor.isClient) { Meteor.startup(function () { $(".button-collapse").sideNav(); }); } 

All good so far

But...

Next I installed added iron:router to my project and after defining routes (and a template) I could see the starter template page again but the sideNav bars are no longer triggered when I 'click' on the hamburger icon.

How can I restore a functioning navigation sidebar?

Simplest answer is to make that $(".button-collapse").sideNav(); call in the onRendered() event function of the template in which the button is found:

<template name="navigation">
  ...
  <a class="button-collapse">...</a>
  ... 
</template>

Template.navigation.onRendered(function(){
   $(".button-collapse").sideNav();
});

This should do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM