Next.js App Router Patterns

Next.js App Router Patterns

Teaches Next.js 14+ App Router patterns: Server Components, streaming, parallel routes, data fetching, caching and Server Actions.

Skill files2 files

references/

SKILL.md115 lines
1
---
2
name: nextjs-app-router-patterns
3
description: Master Next.js 14+ App Router with Server Components, streaming, parallel routes, and advanced data fetching. Use when building Next.js applications, implementing SSR/SSG, or optimizing React Server Components.
4
---
5
6
# Next.js App Router Patterns
7
8
Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.
9
10
## When to Use This Skill
11
12
- Building new Next.js applications with App Router
13
- Migrating from Pages Router to App Router
14
- Implementing Server Components and streaming
15
- Setting up parallel and intercepting routes
16
- Optimizing data fetching and caching
17
- Building full-stack features with Server Actions
18
19
## Core Concepts
20
21
### 1. Rendering Modes
22
23
| Mode | Where | When to Use |
24
| --------------------- | ------------ | ----------------------------------------- |
25
| **Server Components** | Server only | Data fetching, heavy computation, secrets |
26
| **Client Components** | Browser | Interactivity, hooks, browser APIs |
27
| **Static** | Build time | Content that rarely changes |
28
| **Dynamic** | Request time | Personalized or real-time data |
29
| **Streaming** | Progressive | Large pages, slow data sources |
30
31
### 2. File Conventions
32
33
```
34
app/
35
├── layout.tsx # Shared UI wrapper
36
├── page.tsx # Route UI
37
├── loading.tsx # Loading UI (Suspense)
38
├── error.tsx # Error boundary
39
├── not-found.tsx # 404 UI
40
├── route.ts # API endpoint
41
├── template.tsx # Re-mounted layout
42
├── default.tsx # Parallel route fallback
43
└── opengraph-image.tsx # OG image generation
44
```
45
46
## Quick Start
47
48
```typescript
49
// app/layout.tsx
50
import { Inter } from 'next/font/google'
51
import { Providers } from './providers'
52
53
const inter = Inter({ subsets: ['latin'] })
54
55
export const metadata = {
56
title: { default: 'My App', template: '%s | My App' },
57
description: 'Built with Next.js App Router',
58
}
59
60
export default function RootLayout({
61
children,
62
}: {
63
children: React.ReactNode
64
}) {
65
return (
66
<html lang="en" suppressHydrationWarning>
67
<body className={inter.className}>
68
<Providers>{children}</Providers>
69
</body>
70
</html>
71
)
72
}
73
74
// app/page.tsx - Server Component by default
75
async function getProducts() {
76
const res = await fetch('https://api.example.com/products', {
77
next: { revalidate: 3600 }, // ISR: revalidate every hour
78
})
79
return res.json()
80
}
81
82
export default async function HomePage() {
83
const products = await getProducts()
84
85
return (
86
<main>
87
<h1>Products</h1>
88
<ProductGrid products={products} />
89
</main>
90
)
91
}
92
```
93
94
## Detailed patterns and worked examples
95
96
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
97
98
## Best Practices
99
100
### Do's
101
102
- **Start with Server Components** - Add 'use client' only when needed
103
- **Colocate data fetching** - Fetch data where it's used
104
- **Use Suspense boundaries** - Enable streaming for slow data
105
- **Leverage parallel routes** - Independent loading states
106
- **Use Server Actions** - For mutations with progressive enhancement
107
108
### Don'ts
109
110
- **Don't pass serializable data** - Server → Client boundary limitations
111
- **Don't use hooks in Server Components** - No useState, useEffect
112
- **Don't fetch in Client Components** - Use Server Components or React Query
113
- **Don't over-nest layouts** - Each layout adds to the component tree
114
- **Don't ignore loading states** - Always provide loading.tsx or Suspense
115

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…