I'm using Pusher with Laravel Echo to create presence channels for certain areas in my application. All my front-end routing is done using Vue Router.
When switching between routes, Vue router will load certain components based on my routes settings. It works great, however, Pusher doesn't automatically disconnect the users from these channels. It will happen only if I run a full page refresh, which is not what I want.
In my component, the js code to join a Pusher channel is inside mounted
, like this:
data() {
return {
users: [],
}
},
mounted() {
Echo.join('transaction.' + this.tid)
.here(users => {
this.users = users;
}
})
.joining(user => {
this.users.push(user);
})
.leaving(user => {
this.users.splice(this.users.indexOf(user), 1);
});
},
methods: {
// ...
},
How do I disconnect the users from the channels using Vue Router routing, without refreshing the page?
Thank you.
Echo.leave('transaction.' + this.tid);
? – Wilden