skip to Main Content

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

Answers


  1. 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;
    }
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search