How to track page reload?

时间:2019-04-16 22:31:20

标签: javascript node.js express socket.io

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!

0 个答案:

没有答案
相关问题