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:
- Go to some route (e.g., /foo)
- The onBefore function is not executed
- The waitOn function for that route’s controller is executed.
- The onRun function is executed
- 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?