I have a template ("ImageView") displaying collection data, and I use it at two different routes to display different content: at one route it is used to display all data, and at another to display data that belongs to specific user.
Because my layout has various components so I embed the ImageView template within the main template of each route ("Album" and "Profile").
I set up the template level subscription at the two main templates like so:
Template.profile.onCreated ( function() {
Tracker.autorun(function() {
Meteor.subscribe('images', Meteor.userId());
});
});
and
Template.Album.onCreated (function() {
Tracker.autorun(function() {
Meteor.subscribe('images');
}); })
and I have my publication function like so at the server:
Meteor.publish('images', function ( user_id) {
findQuery={}
if (user_id) {
findQuery = {userId: user_id};
}
return Images.find(findQuery);
});
The problem is that, when I navigate between the route between the two pages, the template "ImageView" will not update its content reactively, until I press refresh. (If I enter the url by hand and press enter it will also work fine). Are there cache within the template? But they seemed to be created and destroyed as expected when route changes (checked in onCreated and onDestroyed callbacks).
I have console logged inside the publish function and I made sure the publication is changed when I navigate between the two routes, but the client side is not updating accordingly. I have also tried reactive-publish package, Template.subscriptionReady,FlowRouter.reload() and they don't solve the issue.
Can anyone give me insights on what the issue might be? Btw, I am using FlowRouter.
Any inputs are appreciated. Thank you very much.
You shouldn't use Tracker.autorun
in onCreated
because you would have to stop the computation manually when the template is destroyed. Use this.autorun
instead. It uses the Template autorun.