I am looking for a solution that iron-router is waiting for a successfully find method on my collection before rendering.
My route looks like this:
this.route('business', {
path : '/business/:type/:_id',
waitOn : function () {
return Meteor.subscribe('business', this.params._id);
},
data : function () {
return Business.findOne({_id: this.params._id});
}
});
This works fine. It seems that iron-router is waiting for the subscribe of the Collection to get the right Document back for the client. But the data which i need in my template has a delay for the findOne function.
Template.businessItemItem.rendered = function () {
console.log(Router.current().data()); // undefined
window.setTimeout(function(){
console.log(Router.current().data()); // [Object]
}, 1000);
}
Solution For everyone with the same problem. Just add the "action" method for your route like this:
action : function () {
if (this.ready()) this.render();
}
With this method everything works fine for me.
if (!this.ready()) return;
put as the first line of data() method, as suggested in this post: groups.google.com/forum/#!topic/meteor-talk/lK3v9ZxIbco – Arabian