8

I upgraded to Meteor 1.0, installed the latest iron-router package, tried to run my app and got this nice warning in my console log:

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

So I tried to modify my routes according to the new version.

this.route('gamePage', {
        path: '/game/:slug/',
        onBeforeAction: [function() {
            this.subscribe('singlePlayer', this.params.slug).wait();
            var singlePlayer = this.data();
            if (singlePlayer) {
                if (singlePlayer.upgrade) {
                    this.subscribe('upgrades', this.params.slug).wait();
                    this.next();
                }
                this.next();
            }
            this.next();
        }],
        data: function() {
            return Games.findOne({slug: this.params.slug});
        },
        waitOn: function() { return [Meteor.subscribe('singleGame', this.params.slug)]}
    });

How can I fix this? Any help would be greatly appreciated.

user3475602
  • 1,217
  • 2
  • 21
  • 43

1 Answers1

9

Try removing all the .wait()s and removing the array around your onBefore function.

With the new API this.next() replaces .wait().

benstr
  • 652
  • 4
  • 16
  • Thank you! That works! Do I need 3 x `this.next()` or just once at the end of the function? – user3475602 Nov 02 '14 at 08:21
  • You may not need it for the first `if`. Give it a try and report back. – benstr Nov 02 '14 at 21:18
  • This worked for me: `if (singlePlayer) { if (singlePlayer.upgrade) { this.subscribe('upgrades', this.params.slug).wait(); } } this.next();` Could you please explain where I should place `this.next()` in general? Trial-and-error method is a little bit frustrating. – user3475602 Nov 03 '14 at 08:14
  • 4
    Sorry about that. Basically you need it if your `onBefore` or `onRun` does not result in a `Router.go()` being ran. Which yours does not. IronRouter `onBefore` will run the first command it encounters then stop... unless you call `this.next()`. Then it will do the same thing (run then stop) until either you reach the end of the `onBefore/onRun` logic or a `Router.go` is called. – benstr Nov 03 '14 at 23:46