Next.js Discord

Discord Forum

Multiple page revalidation

Answered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
I am using next with sanity. I want to revalidate pages on demand time. So I am using webhook. I have two documents that's why using two webhooks for two pages. How do I revalidate in next js for two pages. For one page I know to create app/api/revalidate/route.js but what to do when I have more than one page to revalidate ?
Answered by B33fb0n3
then just update your webhook so it call the revalidatePath multiple times:
// ...

revalidatePath("/your/first/path/");
revalidatePath("/your/second/path/");

// ...
View full answer

7 Replies

Asiatic LionOP
@B33fb0n3 No I am using sanity webhook actually to trigger revalidation. When a post is added then only the revalidation will work on that specific path. So I need to know how to do this for multiple pages?
@Asiatic Lion As soon as the a post is created, It would trigger the api route to revalidate. https://www.sanity.io/plugins/next-sanity#path-based-revalidation:~:text=%3E%0A%20%20)%0A%7D-,Path%2Dbased%20revalidation,-For%20on%2Ddemand
then just update your webhook so it call the revalidatePath multiple times:
// ...

revalidatePath("/your/first/path/");
revalidatePath("/your/second/path/");

// ...
Answer
Asiatic LionOP
Yaa it worked with applying if condition. Thank you
happy to help