Multiple page revalidation
Answered
Asiatic Lion posted this in #help-forum
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/");
// ...7 Replies
@Asiatic Lion 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 ?
inside your
route.js you can call the function to revalidate your path multiple times for different locations:// ...
revalidatePath("/your/first/path/");
revalidatePath("/your/second/path/");
// ...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 <@301376057326567425> 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?
the sanity webhook trigger one of your api routes? Or what does the senity webhook trigger?
@B33fb0n3 the sanity webhook trigger one of your api routes? Or what does the senity **webhook** trigger?
Asiatic LionOP
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
https://www.sanity.io/plugins/next-sanity#path-based-revalidation:~:text=%3E%0A%20%20)%0A%7D-,Path%2Dbased%20revalidation,-For%20on%2Ddemand
@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