0

This is the first time I am deploying a web application with react without a webpack and I have this problem which is explained in the react router documentation - you can access only the home page when reloading or directly entering the link.
The problem is described here and I understand I need to instruct the server to redirect with:

app.get("*", (req, res) => {
  res.sendFile(path.resolve(__dirname, "index.html"));
});

But I am a bit confused where I am supposed to put this command?

2
  • If you use Netlify, you can use _redirect file
    – dance2die
    Feb 12, 2019 at 14:45
  • I am not using it but thanks.
    – Zotov
    Feb 12, 2019 at 14:48

1 Answer 1

0

The code sample that you gave is looking like NodeJS/ExpressJS.

It tells the backend server to get any request to the server (that's why the app.get("*", ...) and send in the response, your index.html file.

So, if you need to put this at some place, that example is telling you to put on some app module in your NodeJS/Express server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.