Iron-router waits on Collection.findOne () as a data object before rendering

I am looking for a solution that iron-router is expecting the find method for my collection before rendering.

My route is as follows:

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

It works great. It seems that the iron router is waiting for a subscription to the Collection to get the correct document for the client. But the data that 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 an “action” method for your route as follows:

 action : function () { if (this.ready()) this.render(); } 

With this method, everything works fine for me.

+6
source share
1 answer

I'm not sure I am having problems, but if I do, you should read “Subscription Control” , and especially Router.onBeforeAction('loading') , Now you are reinventing the wheel.

+2
source

All Articles