RevalidatePath, I can't figure the correct path.
Answered
American Crocodile posted this in #help-forum
American CrocodileOP
In the attached image below you can see my folder structure, I want to revalidate the cached images in text-to-image layout.
This is my route handler code.
route.ts
Am I missing something?
it works fine if I want to revalidate everything using
This is my route handler code.
route.ts
import { revalidatePath } from "next/cache";
import { NextResponse } from "next/server";
export async function GET() {
revalidatePath("/[locale]/(products)/text-to-image", "layout");
console.log("revalidating images");
return NextResponse.json({ revalidated: true, now: Date.now() });
}Am I missing something?
it works fine if I want to revalidate everything using
revalidatePath("/", "layout").Answered by American Crocodile
using revalidateTag instead solved my problem.
and in the fetch api I added
import { revalidateTag } from "next/cache";
import { NextResponse } from "next/server";
export async function GET() {
revalidateTag("gallery");
console.log("revalidating images");
return NextResponse.json({ revalidated: true, now: Date.now() });
}and in the fetch api I added
tags const res = await fetch(
`https://${process.env.API_URL}/api/Gallery?${query} `,
{
method: "GET",
headers,
redirect: "follow",
next: {
tags: ["gallery"],
},
},
);1 Reply
American CrocodileOP
using revalidateTag instead solved my problem.
and in the fetch api I added
import { revalidateTag } from "next/cache";
import { NextResponse } from "next/server";
export async function GET() {
revalidateTag("gallery");
console.log("revalidating images");
return NextResponse.json({ revalidated: true, now: Date.now() });
}and in the fetch api I added
tags const res = await fetch(
`https://${process.env.API_URL}/api/Gallery?${query} `,
{
method: "GET",
headers,
redirect: "follow",
next: {
tags: ["gallery"],
},
},
);Answer