Revalidating Tags with App Router
Unanswered
Dwarf Hotot posted this in #help-forum
Dwarf HototOP
I am using revalidateTag, my revalidation request gets the status 200 and my Vercel log sees the revalidation. But the data is the same on my page (even after Ctrl + Shift + R).
If I set cache to no-cache, then I essentialy SSR and the revalidation has no point, no?
If I set cache to no-cache, then I essentialy SSR and the revalidation has no point, no?
...
cache: 'no-cache',
next: {
tags: ['posts'],
},
...5 Replies
Dwarf HototOP
import { NextRequest, NextResponse } from 'next/server';
import { revalidateTag } from 'next/cache';
export async function POST(request: NextRequest) {
const secret = request.nextUrl.searchParams.get('secret');
const tag = request.nextUrl.searchParams.get('tag');
if (secret !== process.env.REVALIDATE_KEY) {
return NextResponse.json({ message: 'Invalid secret!' }, { status: 401 });
}
if (!tag) {
return NextResponse.json(
{ message: 'Missing tag parameter!' },
{ status: 400 }
);
}
revalidateTag(tag);
return NextResponse.json({ revalidated: true, now: Date.now(), tag });
}This is my revalidation code.
And the fetch is using the
posts tag.I am then requesting the URL:
https://myapp.vercel.app/api/revalidate?tag=posts&secret=###Dwarf HototOP
And the routes are correctly in the ISR functions.