0

Hi I uploaded my react app on server and make it live. It's working fine but whenever I refresh any page of application. it's returning 404 error. what should I do ?

2 Answers2

5

When your app load. The react-router handle Router. The Route change is handled by Router itself but on refreshing the request goes to nginx where that specific route doesn't exist.

To resolve this issue you need to load root file. try this solution.

cd /etc/nginx/sites-available
sudo nano default

in default file update location

location {
    try_files $uri /index.html;
}
Ivan Shatsky
  • 13,267
  • 2
  • 21
  • 37
Ejaz khan
  • 1,535
  • 8
  • 17
0

there please add this in your nginx.conf

location / {
 try_files $uri /index.html;
}

The problem is whenever you are trying to refresh the page it cannot find that route on nginx hence you get 404 whereas when you are browsing the app it just works fine because those things are handled by browser itself.

sammyhp
  • 122
  • 3