React Router routes not working on nginx create-react-app React Router routes not working on nginx create-react-app nginx nginx

React Router routes not working on nginx create-react-app


The answer is found in this threadReact-router and nginx

What I had to do was modify default configuration file in /etc/nginx/sites-available/default to:

    location / {            # First attempt to serve request as file, then            # as directory, then fall back to displaying a 404.            try_files $uri /index.html;    }


If you wish to do this in a Dockerfile and run your React app, using nginx please see the below answer.

https://stackoverflow.com/a/61753597/4388776

This fixes the React Router issues where you allow nginx to route traffic coming on different endpoints, directly to you React Application.


The solution that works for me in the live server:

server {        listen 80;        listen [::]:80;        root /var/www/example.com;        index index.html index.htm index.nginx-debian.html;        server_name example.com www.example.com;        location / {                try_files $uri $uri/ /index.html;        }}