Why does socket.io not handle page reload?
I have an express.js application, when reloading the page, app.get('/')
is processed first and then socket.on('disconnect')
. How do I handle disconnect socket first and then go to app.get('/')
for the current page?
app.get('/', (req, res) => {
console.log('express get!')
})
io.on('connection', (socket) => {
socket.on('disconnect', () => {
console.log('socket disconnect!')
})
})
If you reload the page
Console:
express get!
socket disconnect!
Expected behavior:
socket disconnect!
express get!