This project uses React Router for client-side routing. When deployed to production, the server needs to be configured to serve index.html for all routes to enable proper SPA navigation.
This repository includes configuration files for multiple hosting platforms:
Automatically redirects all routes to index.html when deployed to Vercel.
The _redirects file in the public/ folder is copied to the build output and tells Netlify to serve index.html for all routes.
GitHub Pages doesn't support traditional server-side redirects, but there's a workaround:
- Create a
public/404.htmlfile that's a copy of yourindex.html - GitHub Pages serves 404.html for missing routes, which loads your React app
- React Router then handles the routing client-side
- Alternative: Use HashRouter instead of BrowserRouter (URLs will have
#like/#/week2)
For Apache servers, add a .htaccess file in your public directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>React Router uses the browser's History API for client-side navigation. When you:
- Navigate within the app (e.g., click Week 2 button) → Works fine (client-side)
- Directly access a route (e.g., type
/week2in browser) → Server needs to serve index.html - Refresh the page on any route → Server needs to serve index.html
Without proper configuration, the server returns a 404 error because it looks for a physical file at /week2, which doesn't exist in a SPA.
npm run dev - Vite dev server has built-in SPA support, so routing works automatically.
npm run build && npm run preview - Test the production build locally before deployment.
After deployment, test by:
- Navigating to the root URL
- Clicking on week buttons to navigate
- Refreshing the page while on a nested route
- Directly accessing a nested route (e.g.,
yourdomain.com/week2)
All scenarios should work without 404 errors.