When I access to a component, it runs socket.on.
And there is a button component in Vuejs as below.
So when I emit to socket.on('voice') of nodejs, the nodejs socket emits to 'socket.on('reply').
Thus, console.log(msg) worsk well.
<button @click="start()">Click</button>
methods:{
start(){
socket.emit('voice',{data:'hey'})
}
created(){
socket.on('reply', msg => console.log(msg))
But the problem is when I move to another url and back to this component, 'socket.on('reply') runs again.
Therefore there are two websocket clients here.
how can I solve this problem? Thank you so much for reading this.