how to redirect all server requests to index.html file in node.js

Viewed 1550

I have found the solution to error from here

app.get('/*', function(req, res) {
  res.sendFile(path.join(__dirname, 'path/to/your/index.html'), function(err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})

but I am not able to understand what I have actually write in that index.html file

enter image description here

1 Answers

This solved my problem all thanks to @Mosh Feu Who helped me a lot in this problem solving you can see discussion in this chat

NOTE : use index.html file after declaring routes to api

app.use("/api", indexRouter);

app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname, '/build/index.html'), function (err) {
    if (err) {
      res.status(500).send(err)
    }
  })
})
Related