|
5 | 5 | - **React** with TypeScript |
6 | 6 | - **Vite** for dev server and build |
7 | 7 | - **Tailwind CSS** for styling |
8 | | -- **shadcn/ui** (new-york style) for UI components |
| 8 | +- **shadcn/ui** (new-york style) for UI components — **do NOT hand-edit `src/components/ui/` files** |
9 | 9 | - **Magic UI** for animations and effects |
10 | | -- **wouter** with hash routing for static hosting |
| 10 | +- **wouter** with browser routing (`base: "/page-agent"`) |
11 | 11 | - **lucide-react** for icons |
12 | 12 |
|
13 | 13 | ## Component Guidelines |
@@ -53,58 +53,74 @@ Located in `src/components/ui/`: |
53 | 53 | ### Styling Rules |
54 | 54 |
|
55 | 55 | 1. **Prefer Tailwind classes** over custom CSS |
56 | | -2. Use CSS modules only for complex component-specific styles |
57 | | -3. Support dark mode via `dark:` classes |
58 | | -4. Use CSS variables from `src/index.css` for theme colors |
| 56 | +2. Support dark mode via `dark:` classes |
| 57 | +3. Use CSS variables from `src/index.css` for theme colors |
59 | 58 |
|
60 | 59 | ## Project Structure |
61 | 60 |
|
62 | 61 | ``` |
63 | 62 | src/ |
64 | 63 | ├── pages/ |
65 | | -│ ├── Home.tsx # Homepage |
| 64 | +│ ├── home/ |
| 65 | +│ │ ├── HomeContent.tsx # Homepage sections |
| 66 | +│ │ └── ...Section.tsx |
66 | 67 | │ └── docs/ |
67 | | -│ ├── Layout.tsx # Documentation sidebar |
| 68 | +│ ├── index.tsx # Docs route switch |
| 69 | +│ ├── Layout.tsx # Sidebar navigation |
68 | 70 | │ └── [section]/[topic]/page.tsx |
69 | 71 | ├── components/ |
70 | | -│ ├── ui/ # shadcn/ui + Magic UI components |
| 72 | +│ ├── ui/ # shadcn/ui + Magic UI (DO NOT hand-edit) |
| 73 | +│ ├── Heading.tsx # Anchor heading for doc pages |
71 | 74 | │ ├── Header.tsx # Site header |
72 | 75 | │ └── Footer.tsx # Site footer |
73 | 76 | ├── i18n/ # Internationalization |
74 | | -├── router.tsx # Central routing |
| 77 | +├── router.tsx # Root layout + routing |
75 | 78 | └── main.tsx # App entry |
76 | 79 | ``` |
77 | 80 |
|
78 | | -## Adding New Pages |
| 81 | +## Routing |
79 | 82 |
|
80 | | -### Documentation Page |
| 83 | +Uses wouter browser routing with base path for GitHub Pages deployment at `https://alibaba.github.io/page-agent/`. |
81 | 84 |
|
82 | | -1. Create `src/pages/docs/<section>/<slug>/page.tsx` |
83 | | -2. Add route to `src/router.tsx` with `<Header /> + <DocsLayout>` wrapper |
84 | | -3. Add navigation item to `pages/docs/Layout.tsx` |
| 85 | +```tsx |
| 86 | +// main.tsx |
| 87 | +<Router base="/page-agent"> |
| 88 | + <PagesRouter /> |
| 89 | +</Router> |
| 90 | +``` |
85 | 91 |
|
86 | | -## Routing |
| 92 | +**Key rules:** |
87 | 93 |
|
88 | | -Uses hash-based routing for static hosting: |
| 94 | +- Header and Footer live in `router.tsx` **outside** `<Switch>`, so they always see the root router context (`base="/page-agent"`) |
| 95 | +- Docs pages are nested via `<Route path="/docs" nest>`, which creates a child context (`base="/page-agent/docs"`) |
| 96 | +- Inside the docs nest, Link hrefs are relative to `/docs` (e.g. `href="/features/models"`, NOT `href="/docs/features/models"`) |
| 97 | +- **Never use `~` prefix** in Link hrefs — it bypasses the base path entirely |
| 98 | +- Doc page headings use `<Heading id="slug" level={2}>` for anchor links |
89 | 99 |
|
90 | | -```tsx |
91 | | -import { Router } from 'wouter' |
92 | | -import { useHashLocation } from 'wouter/use-hash-location' |
| 100 | +### SPA on GitHub Pages |
93 | 101 |
|
94 | | -;<Router hook={useHashLocation}>{/* routes */}</Router> |
95 | | -``` |
| 102 | +Instead of `404.html` redirects, the build copies `index.html` into every route directory. Add new routes to the `SPA_ROUTES` array in `vite.config.js`. |
| 103 | + |
| 104 | +## Adding New Pages |
| 105 | + |
| 106 | +### Documentation Page |
| 107 | + |
| 108 | +1. Create `src/pages/docs/<section>/<slug>/page.tsx` |
| 109 | +2. Add route in `src/pages/docs/index.tsx` |
| 110 | +3. Add navigation item in `src/pages/docs/Layout.tsx` |
| 111 | +4. Add path to `SPA_ROUTES` in `vite.config.js` |
96 | 112 |
|
97 | 113 | ## Configuration Files |
98 | 114 |
|
99 | 115 | | File | Purpose | |
100 | 116 | | ----------------- | ----------------------- | |
101 | 117 | | `components.json` | shadcn/ui configuration | |
102 | | -| `vite.config.js` | Vite build settings | |
| 118 | +| `vite.config.js` | Vite build + SPA routes | |
103 | 119 | | `tsconfig.json` | TypeScript config | |
104 | 120 |
|
105 | 121 | ## Commands |
106 | 122 |
|
107 | 123 | ```bash |
108 | | -npm start # Dev server (from root) |
| 124 | +npm start # Dev server (from root) |
109 | 125 | npm run build:website # Build website (from root) |
110 | 126 | ``` |
0 commit comments