React Router BrowserRouter leads to "404 Not Found - nginx " error when going to subpage directly without through a home-page click
The problem is that nginx doesn't know what to do with /signin
. You need to change your nginx config (usually in /etc/nginx/conf.d/
) to serve your index.html
regardless of the route. Here is a sample nginx config that might help:
server { listen 80 default_server; server_name /var/www/example.com; root /var/www/example.com; index index.html index.htm; location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; # access_log logs/static.log; # I don't usually include a static log } location ~* \.(?:css|js)$ { try_files $uri =404; expires 1y; access_log off; add_header Cache-Control "public"; } # Any route containing a file extension (e.g. /devicesfile.js) location ~ ^.+\..+$ { try_files $uri =404; } # Any route that doesn't have a file extension (e.g. /devices) location / { try_files $uri $uri/ /index.html; }}
Just simply add try_files $uri $uri/ /index.html;
to location /
block in NGINX configuration file like this:
server { listen 80; server_name localhost; location / { root /build; index index.html; try_files $uri $uri/ /index.html; }}
On location add this
location / {try_files $uri /index.html;}