title: Meteor: Template is displayed although collection is not loaded yet
body: <p>Hi fellow Meteor friends!</p>
  
  <p>Please note: I am using <a href="https://github.com/tmeasday/meteor-router" rel="nofollow noreferrer">Tom's router</a>!</p>
  
  <p>So I'm trying to only display my template when the mongo collection is ready but for some reason it does not work! :(</p>
  
  <p>I first followed this post: <a href="https://stackoverflow.com/questions/15129827/meteor-how-can-i-tell-when-the-database-is-ready">LINK</a></p>
  
  <p>So I have my publish functions in the server.js and I subscribe to these functions inside my router, so no Deps.autorun() involved here (btw: is this the right approach? Deps.autorun() did not work for me properly):</p>
  
  <p>So I have something like:</p>
  
  <pre><code>'/myroute': function(bar) {
  Meteor.subscribe("myCollection", bar, function() {
          Session.set('stuffLoaded', true);
      });
      return 'stuffPage';
  }
  </code></pre>
  
  <p>In the template, where the data loaded from "myCollection" is displayed, I will have something like this:</p>
  
  <pre><code>&lt;template name="stuffPage"&gt;
      {{#if stuffLoaded}}
          &lt;!-- Show the stuff from the collection --&gt;
      {{else}}
          &lt;p&gt;loading!&lt;/p&gt;
      {{/if}}
  &lt;/template&gt;
  </code></pre>
  
  <p>For some reason "loading!" is never displayed.
  Also, for a couple of milliseconds, the "old data" from the last time the same template was displayed (but with another "bar" value provided to the publish function --> different data) is displayed.</p>
  
  <p>This of course is not good at all because for a couple of ms the user can see the old data and suddenly the new data appears.
  To avoid this "flash" I want to display "loading!" until the new data is loaded but again: this does not work for me! :-(</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thx in advance for your help!</p>
  
  <p>EDIT:</p>
  
  <p>Ok so the problem with the answer in the first post provided by @user728291 is the following:</p>
  
  <p>For some reason the router stuff get's called AFTER the Deps.autorun() ... what is wrong here? :( (please note: eventsLoaded == stuffLoaded.)
  Where do you guys put your Deps.autorun() for the subscriptions or in other words: What's your code mockup for this?</p>
  
  <p><img src="https://i.stack.imgur.com/QgbSw.png" alt="my console.log"> </p>
  
  <p>I actually really think that my code mockup is just plain wrong. So how do you make different subscriptions based on the route (or in other words: based on the template which is currently shown)?</p>
  
  <p>AND: Where do you put the Deps.autorun()? Inside the router.add() function? Or just inside of (Meteor.isClient)?</p>