Reputation: 267
I have two routes with two templates. In one of them, the user subscribe to a collection after clicking a button.
'click #play' : function() {
Meteor.call('create_game', this._id, function(error, result){
Meteor.subscribe('game', result);
});
}
What I want to perform is to stop the subscription if the user change route. I could have used the function waitOn of Iron-Router, then the subscription will be cancelled if the user changes route but I want to start the subscription only if the user click not if he just routes.
Upvotes: 1
Views: 300
Reputation: 6147
When you call Meteor.subscribe
, you get a subscription handle as the return value. This handle has a stop()
method that you can call whenever you want to stop a subscription. So what you probably want to do is save this handle somewhere and call it when the route changes:
handle = Meteor.subscribe(...);
In an Iron Router callback:
handle.stop();
Upvotes: 2