Meteor v 1.0 and Iron:Router

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:50:14

问题


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.

Route dispatch never rendered. Did you forget to call this.next() in an 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};
            }
        }
    });
});

回答1:


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

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

You'll need to update it to

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

More information

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

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



来源:https://stackoverflow.com/questions/26629835/meteor-v-1-0-and-ironrouter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!