revalidatePath
revalidatePath
allows you to purge cached data on-demand for a specific path.
Good to know:
revalidatePath
is available in both Node.js and Edge runtimes.revalidatePath
only invalidates the cache when the included path is next visited. This means callingrevalidatePath
with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.
Parameters
path
: Either a string representing the filesystem path associated with the data you want to revalidate (for example,/product/[slug]/page
), or the literal route segment (for example,/product/123
). Must be less than 1024 characters.type
: (optional)'page'
or'layout'
string to change the type of path to revalidate.
Returns
revalidatePath
does not return any value.
Examples
Revalidating A Specific URL
This will revalidate one specific URL on the next page visit.
Revalidating A Page Path
This will revalidate any URL that matches the provided page
file on the next page visit. This will not invalidate pages beneath the specific page. For example, /blog/[slug]
won't invalidate /blog/[slug]/[author]
.
Revalidating A Layout Path
This will revalidate any URL that matches the provided layout
file on the next page visit. This will cause pages beneath with the same layout to revalidate on the next visit. For example, in the above case, /blog/[slug]/[another]
would also revalidate on the next visit.