Moving the posts subscription to the Home route
In order to load the right data for each page, we need to have the subscription in the routes instead of keeping it in the separate subscriptions.js
file.
The iron:router
has a special function called subscriptions()
, which is ideal for that purpose. Using this function, we can reactively update subscriptions belonging to a specific route.
To see it in action, add the subscriptions()
function to our Home
route:
this.route('Home', {
path: '/',
template: 'home',
subscriptions
: function(){
return Meteor.subscribe("lazyload-posts", Session.get('lazyloadLimit'));
}
});
The Session.setDefault('lazyloadLimit', 2) line from the subscriptions.js file needs to be placed at the start of the routes.js
file and before the Router.configure()
function:
if(Meteor.isClient) { Session.setDefault('lazyloadLimit', 2); }
This has to wrapped inside the if(Meteor.isClient){}
condition, as the session object is only available on the client...