This project is now configured with React Router DOM's HashRouter for GitHub Pages compatibility. Hash-based routing ensures all routes work correctly when deployed to GitHub Pages.
- React Router DOM: Installed and configured with HashRouter
- Navigation: Updated to use React Router DOM components (NavLink, useLocation)
- Build Process: Successfully tested - creates optimized production build in
dist/public/ - gh-pages: Installed as dev dependency for deployment
To complete the GitHub Pages setup, you need to manually add these to your package.json:
{
"homepage": "https://your-username.github.io/your-repo-name",
"scripts": {
"build:client": "NODE_ENV=production vite build",
"predeploy": "npm run build:client",
"deploy": "gh-pages -d dist/public"
}
}- Add the
homepagefield with your GitHub Pages URL - Add the build and deployment scripts shown above
# Build and deploy in one command
npm run deploy
# Or manually:
npm run build:client
npx gh-pages -d dist/public- Go to your GitHub repository settings
- Navigate to "Pages" section
- Set source to "Deploy from a branch"
- Select the
gh-pagesbranch - Your app will be available at the homepage URL
- URLs use hash format:
https://your-site.com/#/profile - GitHub Pages serves
index.htmlfor all routes - React Router handles navigation client-side
- Perfect for static hosting environments
- Production build creates optimized files in
dist/public/ - Includes all assets, CSS, and JavaScript bundles
- Ready for static hosting deployment
npm run build:client- Creates production buildgh-pages -d dist/public- Deploys build folder to gh-pages branch- GitHub Pages automatically serves from gh-pages branch
- 404 on routes: Ensure you're using HashRouter (already configured)
- Assets not loading: Check homepage field matches your GitHub Pages URL
- Build fails: Run
npm run build:clientto test build process
- ✅ Hash symbol (#) appears in URLs when navigating
- ✅ Page refreshes work correctly on any route
- ✅ Direct URL access works for all routes
- Update your package.json with the required fields
- Run
npm run deployto deploy to GitHub Pages - Configure your GitHub repository Pages settings
- Your React app will be live on GitHub Pages!