流星v 1.0和Iron:Router [英] Meteor v 1.0 and Iron:Router

查看:58
本文介绍了流星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.

这篇关于流星v 1.0和Iron:Router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆