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


#1

In my router.js:

Router.plugin('dataNotFound', {notFoundTemplate: 'notfound'});

Router.map(function () {
  // 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 [
        Meteor.subscribe('meetings')
      ];
    },
    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!
—t3db0t


#2

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?


#3

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!


#4

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.


#5

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 …


#6

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?


#7

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


#8

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.


#9

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.