流星v 1.0和Iron:Router

流星v 1.0和Iron:Router

问题描述:

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

Is anyone else getting the following error from Iron-Router since upgrading Meteor to version 1.0?

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

Please post here if you know how to resolve this issue.

路由分配从未呈现.您是否忘了在onBeforeAction中调用this.next()?

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};
            }
        }
    });
});

最新版本的Iron Router进行了向后兼容.迁移指南说:

There was a non backwards-compatible change in the newest version of Iron Router. The migration guide says:

onRunonBeforeAction挂钩现在要求您调用this.next(),并且不再使用pause()自变量.因此,默认行为是相反的.例如,如果您有:

onRun and onBeforeAction hooks now require you to call this.next(), and no longer take a pause() argument. So the default behaviour is reversed. For example, if you had:

Router.onBeforeAction(function(pause) {
  if (! Meteor.userId()) {
    this.render('login');
    pause();
  }
});

您需要将其更新为

Router.onBeforeAction(function() {
  if (! Meteor.userId()) {
    this.render('login');
  } else {
    this.next();
  }
});


更多信息

对于您而言,按书上的解决方法是在onBeforeAction的末尾添加this.next().但是,您应该使用waitOn:

In your case, the by-the-book fix would be to add this.next() at the end of onBeforeAction. However, you should rather use waitOn:

waitOn: function () {
  return Meteor.subscribe("userData");
}

这样,您可以设置loadingTemplate,该loadingTemplate将在加载userData订阅时显示.

That way, you can set a loadingTemplate which will appear while the userData subscription is loading.