revalidatePath lets you invalidate cached data on-demand for a specific path.
It can be called in Server Functions and Route Handlers only — not in Client Components or middleware.
Parameters
The route path to invalidate. Can be:
- A literal path:
/blog/post-1 - A route pattern with dynamic segments:
/blog/[slug]
/page or /layout.When
path contains a dynamic segment (e.g. /blog/[slug]), this parameter is required to specify the type of path.'page'— invalidates all pages matching the pattern, but not pages nested beneath them.'layout'— invalidates the layout and all pages beneath it.
path is a literal (e.g. /blog/post-1), omit type.Returns
revalidatePath returns void.
What gets invalidated
| Target | Behavior |
|---|---|
| Specific page | Invalidates that exact page |
Layout with type: 'layout' | Invalidates the layout and all nested pages |
| Route Handler | Invalidates cached data accessed in that handler |
'/' with type: 'layout' | Purges the entire Client Cache and all cached data |
Good to know
- Server Functions: Triggers immediate UI update for the affected path and clears previously visited pages (temporary behavior, will change in a future version).
- Route Handlers: Marks the path for revalidation on the next visit — does not immediately trigger re-rendering.
- When using rewrites, pass the destination path (the actual route file), not the rewritten source URL visible in the browser.
Relationship with revalidateTag
| Function | Scope |
|---|---|
revalidatePath | Invalidates a specific page or layout path |
revalidateTag | Invalidates data with specific cache tags across all pages |
revalidatePath('/blog') only refreshes that page — other pages sharing the same data tags continue to serve stale data until their tags are also invalidated.
Examples
Revalidate a specific page
Revalidate all pages matching a pattern
Revalidate a layout and all pages beneath it
Revalidate all data (entire cache)
In a Server Action
app/actions.ts
In a Route Handler
app/api/revalidate/route.ts
