revalidatePath
를 사용하면 특정 경로와 관련된 데이터를 재검증 할 수 있습니다.
이기능은 재검증 기간이 만료될 때까지 기다리지 않고 캐시된 데이터를 업데이트하려는 시나리오에 유용합니다.
// app/api/revalidate/route.js
import { NextResponse } from 'next/server';
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() });
}
알아두면 유용합니다:
revalidatePath
는 Node.js and Edge runtimes. 모두에서 사용할 수 있습니다.
revalidatePath(path: string): void;
path
: 재검증하려는 데이터와 연결된 경로를 나타내는 문자열입니다.
revalidatePath
는 어떤 값도 반환하지 않습니다.
// app/api/revalidate/route.js
import { NextResponse } from 'next/server';
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() });
}
// app/api/revalidate/route.js
import { NextResponse } from 'next/server';
import { revalidatePath } from 'next/cache';
export const runtime = 'edge';
export async function GET(request) {
const path = request.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ revalidated: true, now: Date.now() });
}