Iron-Router showing notfound template, but still trying to execute a different template's logic


In my router.js:

Router.plugin('dataNotFound', {notFoundTemplate: 'notfound'}); () {
  // only allow access if you're in the participants list or meeting is marked as public
  this.route('meeting', { 
    path: '/meeting/:_id',
    template: 'meeting',
    waitOn: function() {
      return [
    data: function() {
      return Meetings.findOne({"uuid":this.params._id});

When I go to a /meeting/:id route while logged in, everything works as expected. When I am not logged in, the ‘notfound’ template correctly shows, but I see a ton of console errors as it tries to execute the client logic for the ‘meeting’ template! What gives?

I had tried a number of different approaches to routing based on login status, but I’m still not sure what the ‘most correct’ or canonical way to do it is…

Thanks for any help!


Hm, interesting: after some more testing, I found that I only get these errors if the template refreshes automatically, for instance if I click “Sign Out”. If I navigate to the URL by itself on a ‘fresh’ tab, I don’t get these errors.

Any ideas?


Iron-router is difficult to work with because it uses reactive logic that fires off at unpredictable times. Once I switched to Arunoda’s flow-router I found that I was able to more powerfully understand the internal logic of my app. FlowRouter is specifically designed to be simple and predictable. I love it!


Looks very nice—I’ll have to evaluate how much of a refactor it would be to change out routers right now…

Regardless, I’m still curious if anyone know what’s going on with this particular Iron-Router issue.


Try to check in your data function if the route is actually ready

data: function() {
 if(this.ready()) return Meetings.findOne({"uuid":this.params._id});
 else return null;

it turns out that waitOn actually does not block the rest of the route to execute …


Hm; tried this, didn’t prevent the errors upon signing out. FWIW, the errors are all preceded by Exception from Tracker recompute function: so it would seem to be related to the Tracker autorun functions in the template. But still, why is the template code being run at all?


Dont you think you have to show us your template’s code?


I could, of course, but the problem is not in the template code, it’s that the template’s code is being run at all, because the template should not be loaded in the first place.


Man, template logic could not run without template creation. All your helpers, onRendered, onDestroyed etc, events mapping work ONLY if template was CREATED (onCreated callback fires)/ So I cant figure out what are you talkin about.