React + Vite + React Router - 404 on page reload.
Hi all,
We really love your product and we are evaluating to move our current infrastructure to your offered service.
We are running into an issue where we have a React app bundled with Vite and client side routing is handled by react-router@6.
the app builds and deploys fine and we can see the app remotely @ https://piggy-frontend-production.up.railway.app
however when we reload the page we get a 404. we know in order to fix this we need to manually change server rewrites to redirect to /index.html.
This functionality is not present on the project dashboard nor in the railway repo settings. Is this a know issue to you or there is some settings we are not seeing?
hopefully you can help out π
thanks!
React App
Web site created using create-react-app
5 Replies
Unknown Userβ’3y ago
Message Not Public
Sign In & Join Server To View
same here, did you get this solved?
actually i see from the link that you did, could you share the solution? @Jimmy. π
basically the fix for the issue you have is that nginx does not resolves the reload path and you are required to change the server configuration for nginx. unfortunately this is not something Railway supports (for now).
the fix is to wrap the whole react app withing a docker container and run nginx into that container.
STEP 1:
Create a
Dockerfile
at the root of your project and add in it the following code:
Replace those ARG
with your env variables and if you use npm
replace where im using yarn
STEP 2:
Create .nginx/nginx.conf
file at the root of your project and add the following code:
STEP 3:
Add a .dockerignore
file at the root of your project and add the following code:
then all you have to do is to push repo to master and trigger deploy on Railway and the builder will automatically detect you have a Dockerfile
at the root of your project and will run the app with it.
Make sure to remove from Railway UI any start command (leave it empty).
NOTE: if you have setup a PORT
env variable in Railway UI please change the value to 80
so it matches with your nginx config file.
And it should work fine!Thank you!
Unknown Userβ’3y ago
Message Not Public
Sign In & Join Server To View