I’m having trouble getting my create react app build to properly route to my components on my server.
I have a .htaccess file
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]
so that it always routes to my index.html
the url to my site is .com/project and my homepage option in my package.json file is homepage: '/project'
I have ran out of things to do.
Because of my htaccess it’s always routing to my index.html but the router is always loading the 404 component. What am I missing.
2
Answers
This occured because the base routing was wrong so it was constitently routing to the 404 page.
Setting the
<Router basename="/<Directory>">
and adding the homepage option to my package.json file fixed this problem.For me worked with this .htaccess: