- Newest
- Most votes
- Most comments
Hello.
Is "index.html" set in the S3 error document?
I think the following stackoverflow answers will be helpful.
https://stackoverflow.com/questions/51218979/react-router-doesnt-work-in-aws-s3-bucket
https://docs.aws.amazon.com/AmazonS3/latest/userguide/CustomErrorDocSupport.html
I think the following blogs will also be helpful.
https://via.studio/journal/hosting-a-reactjs-app-with-routing-on-aws-s3
By the way, if you plan to switch to HTTPS in the future, I think it would be better to use CloudFront instead of distributing only with S3.
https://stackoverflow.com/questions/16267339/s3-static-website-hosting-route-all-paths-to-index-html
I believe that the current configuration of your vercel.json is redirecting all requests to the root (/). This means that if someone tries to access /about or any other URL, they will be redirected to the homepage (/). This setup doesn't work well with React Router because the router needs an index.html page to start and process the routes.
Please try this code: //vercel.json
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
import React from 'react'; import { BrowserRouter, Routes, Route } from 'react-router-dom'; import Home from './Home'; import About from './About'; import Contact from './Contact'; import Resources from './Resources';
function App() { return ( <BrowserRouter> <Routes> <Route path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/contact" element={<Contact />} /> <Route path="/resources" element={<Resources />} /> </Routes> </BrowserRouter> ); }
export default App;
Thanks Edmilson, Not Working what about on Aws S3 not on Vercel
This Really Helped
https://stackoverflow.com/questions/51218979/react-router-doesnt-work-in-aws-s3-bucket
This is also Good
Relevant content
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
Thanks Riku ✅👍