Meteor v 1.0和Iron:路由器

met*_*uzz 20 meteor iron-router

自从将Meteor升级到1.0版以来,是否有其他人从Iron-Router收到以下错误?

如果您知道如何解决此问题,请在此处发布.

路线调度从未呈现.你忘记打电话this.next()onBeforeAction

Router.map(function () {
    Router.route('profileShow', {

        waitOn: function () {
            if (Meteor.user()) {
                Meteor.subscribe('userData');
            } else {
                this.next();
            }
        },

        data: function () {
            if (Meteor.user()) {
                return {profile: Meteor.user().profile};
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

use*_*348 29

最新版本的Iron Router中存在非向后兼容的更改.迁移指南说:

onRunonBeforeAction钩子现在要求你打电话this.next(),不再pause()争论.因此默认行为是相反的.例如,如果你有:

Router.onBeforeAction(function(pause) {
  if (! Meteor.userId()) {
    this.render('login');
    pause();
  }
});
Run Code Online (Sandbox Code Playgroud)

您需要将其更新为

Router.onBeforeAction(function() {
  if (! Meteor.userId()) {
    this.render('login');
  } else {
    this.next();
  }
});
Run Code Online (Sandbox Code Playgroud)

更多信息

在您的情况下,通过书籍修复将this.next()在最后添加onBeforeAction.但是,您应该使用waitOn:

waitOn: function () {
  return Meteor.subscribe("userData");
}
Run Code Online (Sandbox Code Playgroud)

这样,您可以设置在加载订阅loadingTemplate时显示的userData内容.

  • 只是添加它可能是onRun导致错误,即使消息说它是onBeforeAction.错误消息可能更好. (3认同)