Skilllibrary nextjs-app-router
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/08-web-frontend-and-design/nextjs-app-router" ~/.claude/skills/merceralex397-collab-skilllibrary-nextjs-app-router && rm -rf "$T"
manifest:
08-web-frontend-and-design/nextjs-app-router/SKILL.mdsource content
Purpose
Build Next.js App Router applications with React Server Components, Server Actions, route groups, and correct client/server boundaries.
When to use this skill
- creating routes, layouts, and pages with App Router conventions
- deciding which components should be Server vs Client Components
- implementing data mutations with Server Actions
- using route groups, parallel routes, or intercepting routes
Do not use this skill when
- working with Next.js Pages Router — different patterns
- building non-Next.js React apps — prefer
react-typescript - doing state management — prefer
state-management
Procedure
- Create route structure —
(home),app/page.tsx
(route). Useapp/dashboard/page.tsx
for shared UI.layout.tsx - Default to Server Components — only add
when you need hooks, event handlers, or browser APIs.'use client' - Fetch data in Server Components — use
server components with directasync
or DB calls. Nofetch()
for data fetching.useEffect - Implement mutations — create Server Actions with
in a separate file. Call from'use server'
or<form action={myAction}>
.useTransition - Use route groups —
and(marketing)/
for separate layouts without affecting URL.(app)/
.(auth)/login/page.tsx - Handle loading/error — add
for Suspense fallback andloading.tsx
(client component) for error boundaries per route.error.tsx - Configure metadata — export
object ormetadata
function fromgenerateMetadata()
orpage.tsx
.layout.tsx - Deploy — verify
succeeds. Check static vs dynamic rendering in build output.next build
Server vs Client Components
Server Component (default): Client Component ('use client'): - async/await for data - useState, useEffect, useRef - Direct DB/API access - onClick, onChange handlers - Access secrets/env vars - Browser APIs (localStorage, etc.) - Zero JS sent to client - Interactive UI elements - Cannot use hooks - Cannot be async
Server Actions
// app/actions.ts 'use server'; import { revalidatePath } from 'next/cache'; export async function createPost(formData: FormData) { const title = formData.get('title') as string; await db.post.create({ data: { title } }); revalidatePath('/posts'); } // app/posts/new/page.tsx import { createPost } from '@/app/actions'; export default function NewPost() { return ( <form action={createPost}> <input name="title" required /> <button type="submit">Create</button> </form> ); }
Route groups and parallel routes
app/ (marketing)/ layout.tsx # marketing layout page.tsx # / about/page.tsx # /about (dashboard)/ layout.tsx # dashboard layout (with sidebar) overview/page.tsx # /overview @modal/(.)edit/[id]/page.tsx # intercepting route for modal
Decision rules
- Server Components by default — only opt into
when required.'use client' - Colocate Server Actions in
files — not inline in components.actions.ts - Use
orrevalidatePath()
after mutations — do not manually refetch.revalidateTag() - Put
at route segment level — Next.js wraps the page inloading.tsx
automatically.Suspense - Prefer
overgenerateMetadata
— it supports dynamic metadata with data fetching.<Head>
References
- https://nextjs.org/docs/app
- https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations
Related skills
— component typing patternsreact-typescript
— client-side state alongside RSCstate-management
— testing Server Components and Actionstesting-web