Answer the question
In order to leave comments, you need to log in
How to do routing in a React app?
I have a React web application hosted at site.local/app . I use react-router to navigate it, but when I go to any page, /app is erased , and site.local/app/about is replaced by site.local/about .
Accordingly, when I refresh the page, I get a 404 error, because there is simply no such file. How to solve this problem? Here is my .htaccess config:
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question