Answer the question
In order to leave comments, you need to log in
How to fix 404 error when reloading application with react-router?
There is a react app based on create-react-app, with react-router (Browser routing).
I raise the application locally using nginx.
For example, I follow links to localhost/page/group
The application and routing work correctly.
But if, for example, to refresh the page, then a 404 error is given.
nginx config
server {
listen 80;
server_name app.ru;
rewrite ^/spa/(.*) /$1 permanent;
root build;
index index.html;
location / {
try_files $uri /$uri /index.html;
}
}
Answer the question
In order to leave comments, you need to log in
You need to return index.html from all routes except those that end in .css/.js for example.
server {
...
location / {
alias /static/folder;
try_files /index.html /index.html;
}
location /assets {
alias /static/folder/assets;
}
location ~ .+\.(css|js) {
alias /static/folder;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question