Agent-skills-standard nextjs-pages-router
Implement Pages Router data fetching with getServerSideProps, getStaticProps, and API routes in Next.js legacy projects. Use when working in a pages/ directory project, adding SSR/SSG data fetching, or creating API routes. (triggers: pages/**/*.tsx, pages/**/*.ts, Pages Router, getServerSideProps, getStaticProps, _app, useRouter)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nextjs/nextjs-pages-router" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nextjs-pages-router && rm -rf "$T"
manifest:
skills/nextjs/nextjs-pages-router/SKILL.mdsource content
Next.js Pages Router (Legacy)
Priority: P0 (CRITICAL)
[!IMPORTANT] project uses Next.js Pages Router (
directory). NOT use App Router features.pages/
Workflow: Add Server-Rendered Page
- Create page file — Add
.pages/posts/[id].tsx - Add data fetching — Export
orgetServerSideProps
+getStaticProps
.getStaticPaths - Import service directly — Never fetch your own
routes from server-side hooks./api - Type props — Use
.InferGetServerSidePropsType<typeof getServerSideProps>
getServerSideProps Example
Implementation Guidelines
- Routing Architecture: Use
directory. Usepages/
for global state/layouts and_app.tsx
for custom HTML attributes. Define dynamic routes using brackets_document.tsx
or catch-all[id].tsx
.[...slug].tsx - Data Fetching (SSR/SSG): Use
(for every request) orgetServerSideProps
(at build time) withgetStaticProps
for dynamic routes. Export these as standalonegetStaticPaths
functions.async - Logic Isolation: Never
your ownfetch
endpoints from Server-Side hooks. Import service layer or DB logic directly./api - Client Hooks: Use
fromuseRouter()
for navigation and access to query params. Usenext/router
orrouter.push()
for client-side routing.<Link> - APIs: Implement API Routes in
for server-only logic or webhooks. Standardize responses with appropriate HTTP status codes.pages/api/ - Next.js 15+ Compatibility: cautious of Next.js 15 upgrades; ensure all
return objects that match expectedgetServerSideProps
.PageProps - Styling: Standardize via CSS Modules (
) or Tailwind CSS. Avoid global CSS unless imported in*.module.css
._app.tsx
Anti-Patterns
- No fetching own /api routes from SSR: Import service layer directly.
- No global CSS outside _app.tsx: Use CSS Modules or Tailwind for scoped styles.
- No App Router features in Pages Router projects: Avoid
directory patterns.app/