完全混淆了流星铁路由器中的this.next()

use*_*602 8 javascript meteor iron-router

我升级到Meteor 1.0,安装了最新的铁路由器包,尝试运行我的应用程序并在我的控制台日志中得到了这个好警告:

路线调度从未呈现.你忘了在onBeforeAction中调用this.next()吗?

所以我尝试根据新版本修改我的路线.

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)]}
    });
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?任何帮助将不胜感激.

ben*_*str 9

尝试删除所有.wait()s并删除onBefore函数周围的数组.

随着新的API this.next()取代.wait().

  • 对于那个很抱歉.基本上你需要它,如果你的`onBefore`或`onRun`不会导致`Router.go()`被运行.你的不是.IronRouter`onBefore`将运行它遇到的第一个命令然后停止...除非你调用`this.next()`.然后它将执行相同的操作(运行然后停止),直到您到达`onBefore/onRun`逻辑的末尾或者调用`Router.go`. (4认同)