【问题标题】:Meteor v 1.0 and Iron:RouterMeteor v 1.0 和 Iron:Router
【发布时间】:2014-12-25 03:02:46
【问题描述】:

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

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

路由调度从未渲染。您是否忘记在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};
            }
        }
    });
});

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    最新版本的 Iron Router 有一个不向后兼容的更改。迁移指南说:

    onRunonBeforeAction 挂钩现在要求您调用 this.next(),并且不再采用 pause() 参数。所以默认行为是相反的。例如,如果您有:

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

    您需要将其更新为

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

    More information

    在您的情况下,按常规解决方法是在 onBeforeAction 的末尾添加 this.next()。但是,您应该使用waitOn

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

    这样,您可以设置一个loadingTemplate,它将在userData 订阅加载时出现。

    【讨论】:

    • 只是补充一点,即使消息说它是 onBeforeAction,它也可能是导致错误的 onRun。错误信息可能会更好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 2018-11-04
    相关资源
    最近更新 更多