this.next() error in Meteor Iron Router

509 views Asked by At

Getting a strange error in Meteor:

Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?

and none of the content is rendering. How can I fix this? Any help greatly appreciated.

Here's my router.js

Router.configure({
    layoutTemplate: 'layout',
});

Router.route('/', function() {
    this.render('home');
});

Router.route('/user/:_username', {
  name: 'user_profile',
  data: function() { return Meteor.user();} 
});

Router.route('/create', function() {
  this.render('create_event');
});

Router.route('/events/:name', {
  name: 'event',
  data: function() { return Events.findOne({name: this.params.name});}
});



Router.route('/useremail', function() {
    this.render('userEmail');
}, {
    name: 'userEmail'
});

Router._filters = {
  hasCompletedProfile: function() {
    if(!this.ready()) return;
    var user = Meteor.user();
    if (user && ! userProfileComplete(user)){
      this.render('userEmail');
    } else {
      this.next();
    }
  },
};

filters = Router._filters;
Router.onBeforeAction(filters.hasCompletedProfile);
1

There are 1 answers

0
Barry Michael Doyle On

Make sure you always call this.next(); in your Router._filters method and not just on a condition.

Try replace your Router._filters method with this:

Router._filters = {
  hasCompletedProfile: function() {
    if(!this.ready()) return;
    var user = Meteor.user();
    if (user && ! userProfileComplete(user)){
      this.render('userEmail');
    }
    this.next();  // Take note, it is no longer in an else statement
  },
};