I’m experiencing an issue with routing in my React + Vite project deployed on Netlify.
Locally, everything works fine, and unknown routes are correctly redirected to index.html
. However, on Netlify, the redirection doesn’t work, even with a _redirects
file in the public
folder or a netlify.toml
file containing the following:
[redirects]
from = "/*"
to = "/index.html"
status = 200
I have read previous discussions about similar issues and tried all the recommended steps, including ensuring the _redirects
file is correctly located in the public
folder. However, the problem persists.
The only solution that worked was switching from BrowserRouter
to HashRouter
, which redirects all unknown routes to the base route due to its hash-based approach. While this works, I don’t prefer this solution as it changes the URL structure and doesn’t align with how my application should function.
I don’t recall facing this issue previously, and it seems like _redirects
or netlify.toml
used to handle these scenarios properly.
Could you help me identify if there is a change in behavior or additional steps I need to take to make BrowserRouter
and _redirects
work as expected?
Thank you!