Skip to content

Commit 1b90b03

Browse files
committed
docs: Configure routing for GitHub Pages deployment
1 parent d1532e8 commit 1b90b03

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ Contact form (src/app/pages/contact/Contact.tsx:6):
119119
- onSubmit handler prevents default, logs data, shows alert, resets form
120120
- No backend integration - implement API call in handleSubmit as needed
121121

122+
### GitHub Pages Routing
123+
The app is configured to work with GitHub Pages base paths:
124+
- `BrowserRouter` uses `basename={import.meta.env.BASE_URL}` (src/App.tsx:22)
125+
- `BASE_URL` comes from `vite.config.ts` base setting
126+
- `public/404.html` handles client-side routing on GitHub Pages
127+
- `index.html` includes redirect handler for SPA navigation
128+
129+
When deployed to GitHub Pages, the base path (e.g., `/react-tailwind-template/`) is automatically applied to all routes. For local development, `BASE_URL` is `/`.
130+
122131
### File Extensions
123132
- `.tsx` - React components with JSX
124133
- `.ts` - TypeScript without JSX (barrel exports, utils)

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>React Vite Tailwind Template</title>
8+
<script>
9+
// GitHub Pages SPA redirect handler
10+
(function() {
11+
var redirect = sessionStorage.getItem('redirect');
12+
sessionStorage.removeItem('redirect');
13+
if (redirect && redirect !== location.href) {
14+
history.replaceState(null, null, redirect);
15+
}
16+
})();
17+
</script>
818
</head>
919
<body>
1020
<div id="root"></div>

public/404.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Redirecting...</title>
6+
<script>
7+
// GitHub Pages 404 handler for client-side routing
8+
// This script takes the current full path and redirects to the index page
9+
// with the path as a query parameter, which is then handled by the SPA
10+
sessionStorage.setItem('redirect', location.href);
11+
location.replace(location.origin + location.pathname.split('/').slice(0, -1).join('/') + '/?redirect=' + encodeURIComponent(location.pathname + location.search + location.hash));
12+
</script>
13+
</head>
14+
<body>
15+
</body>
16+
</html>

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const AppRoutes = () => {
1919

2020
const App = () => {
2121
return (
22-
<BrowserRouter>
22+
<BrowserRouter basename={import.meta.env.BASE_URL}>
2323
<div className="page-container">
2424
<Header />
2525
<div className="content-wrapper">

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ import react from '@vitejs/plugin-react'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7-
// IMPORTANT: Update this to match your GitHub repository name
8-
base: '/react-vite-tailwind-template/',
7+
base: '/react-tailwind-template/',
98
})

0 commit comments

Comments
 (0)