Repository navigation
revalidate not working for dynamic App Router route unless generateStaticParams() is added
#94976
SummaryI’m trying to understand the correct caching/revalidation behavior for a dynamic route in the Next.js App Router. I have a dynamic route like My expectation is:
But in production, the route seems to behave as fully dynamic unless I add When I add: export const dynamicParams = true
export async function generateStaticParams() {
return []
}Additional informationExample route:
tsx
// app/blog/[slug]/page.tsx
export const revalidate = 86400
type PageProps = {
params: Promise<{
slug: string
}>
}
export default async function BlogPostPage({ params }: PageProps) {
const { slug } = await params
const post = await fetch(`https://example.com/api/posts/${slug}`, {
next: {
revalidate: 86400,
},
}).then((res) => res.json())
return (
<main>
<h1>{post.title}</h1>
<article>{post.content}</article>
</main>
)
}ExampleExample ```txt No minimal reproduction yet, but the behavior is around a dynamic App Router route using revalidate with and without generateStaticParams(). |
Replies: 1 comment 1 reply
|
Not sure why this was closed and reopened, but from the behavior described, this looks expected in the App Router rather than a bug. For dynamic routes, For large blogs/products/catalogs, this pattern works well: export const revalidate = 86400
export const dynamicParams = true
export async function generateStaticParams() {
return []
}This means no slugs are generated at build time, unknown slugs are allowed at runtime, and the page can be generated on first request, cached, and revalidated later. Just make sure the route is not forced dynamic by things like So yes, for dynamic App Router ISR, using If this solves your case, marking it as the answer can help others find it faster. |
Not sure why this was closed and reopened, but from the behavior described, this looks expected in the App Router rather than a bug.
For dynamic routes,
revalidatealone does not always mean unknown slugs will be generated on first request and cached like ISR. Next needs the route to be statically generatable.For large blogs/products/catalogs, this pattern works well:
This means no slugs are generated at build time, unknown slugs are allowed at runtime, and the page can be generated on first request, cached, and revalidated later.
Just make sure the route is not…