Z
Z
Zhenya Starikov2020-07-20 09:14:22
React
Zhenya Starikov, 2020-07-20 09:14:22

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

1 answer(s)
M
McBernar, 2020-07-20
@McBernar

Homepage must be added to package.json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question