Closed dpatte closed 7 years ago
under /server I have the following:
Meteor.publish('baseData', function() { return [File.find(), Catalog.find()]; });
under /lib I have the following:
Router.configure({ waitOn() { return Meteor.subscribe('baseData'); }, loadingTemplate: 'loading', layoutTemplate: 'layout', });
Router.route('/', { name: 'home', });
Router.route('/catalog/:_manu', { name: 'catalog', data() { // we have an issue here in that Catalog may not be loaded yet // because data() runs this function without checking waitOn first let manu = Catalog.find().fetch(); for (let i=manu.length; i--;) if (cleanURL(manu[i].name)==this.params._manu) return manu[i]; this.render("notFound"); }, });
When the subscription is ready (particularly after a page refresh) it shows not found template. but the data function works after that when selecting other pages.
hey @dpatte, check out the guide info on subscriptions/waitOn http://iron-meteor.github.io/iron-router/#subscriptions
waiting on a subscription stops the route from being rendered, but it doesn't stop the data function from being called
also, your find().fetch()
may be causing some weirdness/re-running of the hooks because they are reactive
then what to do when the data() function is dependent on knowing data is available.
i think you can just check this.ready()
this can cause incorrect data to be shown once the subscription is ready.