Skip to content

Commit 660614b

Browse files
authored
Expand README for src/pages (#58888)
1 parent 8935a97 commit 660614b

1 file changed

Lines changed: 138 additions & 4 deletions

File tree

src/pages/README.md

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,143 @@
11
# Pages
22

3-
This is the Next.js pages directory.
3+
The pages subject is the Next.js pages directory that defines route structure for docs.github.com. This directory acts as a thin routing layer that delegates to actual page implementations in subject-specific directories.
44

5-
See <https://nextjs.org/docs/pages/building-your-application/configuring/src-directory>
5+
## Purpose & Scope
66

7-
There is almost no code in this directory, instead the actual pages live with their subject siblings. These files directly export from the page files in the relative subjects.
7+
This subject is responsible for:
8+
* Defining Next.js routes using file-system routing
9+
* Re-exporting page components from subject directories
10+
* Custom `_app.tsx` for application wrapper
11+
* Custom `_document.tsx` for HTML document structure
12+
* Custom `_error.tsx` for error page handling
13+
* Route structure matching content hierarchy
14+
15+
Note: Actual page implementations live in subject directories (e.g., `src/landings/pages/`, `src/rest/pages/`). This directory contains mostly re-exports and special Next.js files.
16+
17+
## Architecture & Key Assets
18+
19+
### Key capabilities and their locations
20+
21+
- `_app.tsx` - Application wrapper, imports global styles, re-exports from `@/frame/pages/app`
22+
- `_document.tsx` - Custom HTML document with styled-components SSR and color scheme defaults
23+
- `_error.tsx` - Error page that reports to Failbot on server-side errors
24+
- `index.tsx` - Homepage, re-exports from `@/landings/pages/home`
25+
- `[versionId]/[productId]/index.tsx` - Product/category pages, re-exports from `@/landings/pages/product`
26+
27+
## Setup & Usage
28+
29+
### File-system routing
30+
31+
Next.js uses file-system routing where file paths map to URLs:
32+
- `pages/index.tsx``/`
33+
- `pages/search.tsx``/search`
34+
- `pages/[versionId]/index.tsx``/free-pro-team@latest`, `/enterprise-server@3.11`, etc.
35+
- `pages/[versionId]/[productId]/index.tsx``/free-pro-team@latest/actions`, etc.
36+
37+
Dynamic segments use brackets: `[versionId]`, `[productId]`
38+
39+
### Page delegation pattern
40+
41+
Most files in this directory are simple re-exports:
42+
43+
```typescript
44+
// pages/index.tsx
45+
export { default, getServerSideProps } from '@/landings/pages/home'
46+
```
47+
48+
This keeps routing logic in `src/pages/` while page implementation stays with its subject.
49+
50+
### Special Next.js files
51+
52+
- `_app.tsx` - Wraps every page, initializes global state, imports styles
53+
- `_document.tsx` - Customizes HTML structure, handles styled-components SSR
54+
- `_error.tsx` - Renders error pages, reports server-side errors to Failbot
55+
56+
### Adding a new route
57+
58+
1. Determine the URL structure
59+
2. Create file in `src/pages/` matching the route
60+
3. Implement page component in appropriate subject directory
61+
4. Re-export from `src/pages/` file:
62+
```typescript
63+
export { default, getServerSideProps } from '@/my-subject/pages/my-page'
64+
```
65+
66+
## Data & External Dependencies
67+
68+
### Dependencies
69+
- Next.js pages router (being migrated to app router)
70+
- Subject page implementations (`@/landings`, `@/rest`, `@/search`, etc.)
71+
- `@/frame` - Application wrapper and global styles
72+
- styled-components - CSS-in-JS for server-side rendering
73+
74+
### Route resolution
75+
1. Next.js matches incoming URL to file in `src/pages/`
76+
2. Imports re-exported component from subject directory
77+
3. Calls `getServerSideProps` if present
78+
4. Renders page with data
79+
80+
## Cross-links & Ownership
81+
82+
### Related subjects
83+
- [`src/frame`](../frame/README.md) - Provides `_app` implementation and global infrastructure
84+
- [`src/landings`](../landings/README.md) - Homepage and product/category pages
85+
- [`src/rest`](../rest/README.md) - REST API documentation pages
86+
- [`src/graphql`](../graphql/README.md) - GraphQL API documentation pages
87+
- [`src/webhooks`](../webhooks/README.md) - Webhooks documentation pages
88+
- [`src/search`](../search/README.md) - Search pages
89+
- All subjects with `pages/` directories
90+
91+
### Ownership
92+
- Team: Docs Engineering
93+
94+
## Current State & Next Steps
95+
96+
### Migration in progress
97+
We are migrating from Next.js pages router to app router:
98+
- New pages should use app router in `src/app/`
99+
- Pages router in `src/pages/` is legacy
100+
- Migration tracked in internal issue
101+
102+
### Known limitations
103+
- Pages router is deprecated by Next.js in favor of app router
104+
- Some code still exists in `_error.tsx` and `_document.tsx` that should be moved
105+
- Route structure tightly coupled to content hierarchy
106+
107+
### When to edit files here
108+
109+
Edit `_app.tsx`:
110+
- Never (it's a re-export from `@/frame/pages/app`)
111+
112+
Edit `_document.tsx`:
113+
- Only for global HTML document changes
114+
- styled-components SSR configuration
115+
- Default color scheme values
116+
117+
Edit `_error.tsx`:
118+
- Only for global error handling changes
119+
- Failbot reporting configuration
120+
121+
Add new route files:
122+
- When defining new URL structures
123+
- Usually just re-export from subject directory
124+
125+
### App router migration
126+
127+
For new features, use app router:
128+
- Routes defined in `src/app/` instead of `src/pages/`
129+
- Layouts instead of `_app.tsx`
130+
- Error boundaries instead of `_error.tsx`
131+
- New routing conventions with `page.tsx`, `layout.tsx`, etc.
132+
133+
See Next.js documentation for app router migration guide.
134+
135+
### Testing route changes
136+
137+
```bash
138+
npm run dev
139+
# Access routes in browser to verify they work
140+
```
141+
142+
Routes should load without errors and render correct content from subject directories.
8143

9-
TODO migrate code out of `_error.tsx`, `_document.tsx`, and `404.tsx`.

0 commit comments

Comments
 (0)