revalidatePath()
Purges the cached data and rendering for a specific path on demand.
Syntax
import { revalidatePath } from 'next/cache'; revalidatePath(path, type?) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string | Yes | Route to revalidate (literal like `/blog` or a route pattern such as `/blog/[slug]`). |
type | 'page' | 'layout' | No | Whether to revalidate just the page or the whole layout subtree. |
Returns
void — Invalidates the cache; next visit re-renders.
Examples
'use server'
import { revalidatePath } from 'next/cache'
export async function addComment(postId: string, text: string) {
await db.comments.create({ postId, text })
revalidatePath(`/posts/${postId}`)
}
// Revalidate a dynamic segment pattern + its layout
revalidatePath('/products/[id]', 'page')
revalidatePath('/dashboard', 'layout')
Notes
Call from Server Actions or Route Handlers after a mutation to make
the next request fetch fresh data and re-render. It invalidates the
Next.js Data Cache and Full Route Cache for the path. For dynamic
routes pass the pattern (with brackets), not a specific URL, to
revalidate all instances. Server-only.