diff --git a/docs/02-app/02-api-reference/04-functions/revalidatePath.mdx b/docs/02-app/02-api-reference/04-functions/revalidatePath.mdx index 95fb76db826a..abc0b6c9f6f7 100644 --- a/docs/02-app/02-api-reference/04-functions/revalidatePath.mdx +++ b/docs/02-app/02-api-reference/04-functions/revalidatePath.mdx @@ -41,13 +41,22 @@ export default async function submit() { ### Route Handler ```ts filename="app/api/revalidate/route.ts" switcher -import { NextRequest, NextResponse } from 'next/server' import { revalidatePath } from 'next/cache' +import { NextRequest, NextResponse } from 'next/server' export async function GET(request: NextRequest) { const path = request.nextUrl.searchParams.get('path') - revalidatePath(path) - return NextResponse.json({ revalidated: true, now: Date.now() }) + + if (path) { + revalidatePath(path) + return NextResponse.json({ revalidated: true, now: Date.now() }) + } + + return NextResponse.json({ + revalidated: false, + now: Date.now(), + message: 'Missing path to revalidate', + }) } ``` @@ -57,7 +66,16 @@ import { revalidatePath } from 'next/cache' export async function GET(request) { const path = request.nextUrl.searchParams.get('path') - revalidatePath(path) - return NextResponse.json({ revalidated: true, now: Date.now() }) + + if (path) { + revalidatePath(path) + return NextResponse.json({ revalidated: true, now: Date.now() }) + } + + return NextResponse.json({ + revalidated: false, + now: Date.now(), + message: 'Missing path to revalidate', + }) } ```