Meteor - iron-router not waiting on subscription data in onBeforeAction hook

别说谁变了你拦得住时间么 提交于 2019-12-06 21:47:27

Iron Router works fine.

this.subscribe is like Meteor.subscribe and Iron-Router doesn't wait for this.

waitOn is the function that will wait until each of your returned subscriptions are ready that is why this.ready() is true in onBeforeAction

There are several ways of doing what you want

  • You could do it like CodeChimp said by using templates with create/destroyed
  • You could split your route in different routes so that you redirect when it's needed
  • you could use .wait() from the new API of iron router here.

It helped me to wait for the subscribing (until the subscription is really ready) in data function, like this:

Router.route('/:_id', {
    name: 'show',
    template: 'show',
    waitOn: function () {

        var id = this.params._id;
        return Meteor.subscribe('something', id, {});
    },
    data: function () {

        if (this.ready()) {
            var id = this.params._id;
            var data = Somethings.findOne({_id: id});
            return data;
        }
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!