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.
I'm not sure if I get your problem, but if I do, you should read about Controlling subscriptions, and especially Router.onBeforeAction('loading')
. Now, you're reinventing the wheel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With