Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Function

revalidatePath

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.

How it works

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.

Syntax

revalidatePath(path: string, type?: 'page' | 'layout'): void;

Parameters

NameTypeDescription
pathstringA 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.

Returns

void; the function does not return a value.

Key points

  • It provides path-based, on-demand invalidation for cached data.
  • The target may be a page, a layout, or cached data accessed by a route handler.
  • A layout target invalidates that layout, descendant layouts, and descendant pages.
  • Literal URLs identify one concrete resource and therefore do not need the type argument.
  • Its return type is void; it performs invalidation without producing a result.
  • Supported server entry points are Server Functions and Route Handlers.

Common mistakes

  • Use it only in server-side code, such as a Server Function or Route Handler; Client Components and Proxy are unsupported.
  • Pass the route pattern without a /page or /layout suffix and use the optional type argument.
  • Dynamic route patterns must include type, whereas literal paths omit it.
  • Invalidation does not immediately regenerate every matching dynamic route; regeneration happens on a later visit.

Example: Invalidate a specific product URL

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.

When to use it

Refresh a mutated resource

After creating, editing, or deleting content, invalidate the affected route so the next request can render current data.

Revalidate dynamic pages

Invalidate a route pattern such as /blog/[slug] when many dynamic pages share the same page definition.

Refresh a route subtree

Invalidate a section layout and its descendants when shared navigation or metadata changes.

Invalidate route-handler data

Clear cached data accessed by a route handler after a server-side mutation.

Interview questions

QWhat does 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.

QWhen is the 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.

QWhere can 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.

  • revalidateTag
  • Route Handlers
  • Server Functions
  • layout.tsx
  • Data Cache

Source: Next.js. Checked 2026-10-15.