IronRouter not invoking onBefore function, executes waitOn function then hangs after onRun function

I have the following setup for Iron Router (v1.0.7):

var requireLogin = function () {
    if (Meteor.loggingIn()) {
        this.render('loading');
    } else if (!Meteor.user()) {
        this.redirect('/');
    } else{
        this.next();
    }
};

Router.onBeforeAction(requireLogin, {
    except: ['root']
});

The idea here is that any route (except ‘root’) should redirect to root if the user is not logged in.

However, the following behavior is what I’m seeing:

  1. Go to some route (e.g., /foo)
  2. The onBefore function is not executed
  3. The waitOn function for that route’s controller is executed.
  4. The onRun function is executed
  5. Routing hangs with the loading template at this point

What I expect to happen is that when I attempt to navigate to any route (except ‘root’) the first thing that should execute is the onBeforeAction function. Maybe my assumption is wrong here. Maybe I have things setup wrong. Maybe there’s an Iron Router bug I’m unaware of.

Anyone have any thoughts?

1 Like

There’s an issue open for this here

Thanks Oliver! Looks like there are some possible work arounds there too.

1 Like