Refresh a mutated resource
After creating, editing, or deleting content, invalidate the affected route so the next request can render current data.
Next.js 16+ · Function
revalidatePath invalidates cached data on demand for a specified Next.js path. Use it in Server Functions or Route Handlers after mutations; dynamic route patterns require a page or layout type.
Call revalidatePath from a Server Function or Route Handler after a mutation to invalidate cached data associated with a page, layout, or route handler. A literal URL targets one resource, while a dynamic route pattern requires type to specify whether the target is a page or layout; regeneration occurs when the path is visited again.
revalidatePath(path: string, type?: 'page' | 'layout'): void;| Name | Type | Description |
|---|---|---|
path | string | A route file structure or literal URL, such as /product/123, or a dynamic route pattern, such as /product/[slug]. Do not append /page or /layout. |
type | 'page' | 'layout' | Optional path kind: 'page' or 'layout'. Required when path contains a dynamic segment. |
void; the function does not return a value.
void; it performs invalidation without producing a result./page or /layout suffix and use the optional type argument.type, whereas literal paths omit it.import { revalidatePath } from 'next/cache'
export async function updateProduct(id: string) {
// Mutate the product in a database here
revalidatePath(`/product/${id}`)
}After updating a product, invalidate that product URL so its cached data is refreshed on its next visit.
After creating, editing, or deleting content, invalidate the affected route so the next request can render current data.
Invalidate a route pattern such as /blog/[slug] when many dynamic pages share the same page definition.
Invalidate a section layout and its descendants when shared navigation or metadata changes.
Clear cached data accessed by a route handler after a server-side mutation.
revalidatePath do?It invalidates cached data for a specified path on demand. The call can target a literal URL or a dynamic route pattern, and it returns nothing.
Follow-up: How do you invalidate all pages beneath a layout? Use the layout route pattern and pass type as 'layout'; this also covers nested layouts beneath that segment.
type argument required?Use a literal path such as /product/123 without a type argument. For a pattern such as /product/[slug], pass 'page' or 'layout' as the second argument.
Follow-up: Why is the type required for a pattern? The dynamic pattern alone does not identify whether the page or layout cache hierarchy should be invalidated.
revalidatePath be called?It is supported in Server Functions and Route Handlers, not Client Components or Proxy. In a Route Handler, the path is marked for later revalidation on the next visit.
Follow-up: How does this differ from a Server Function? A Server Function can cause previously visited pages to refresh when navigated to again, while a Route Handler defers revalidation until the specified path is visited.
revalidateTagRoute HandlersServer Functionslayout.tsxData Cache