ISR in app dir
Answered
Japanese anchovy posted this in #help-forum
Japanese anchovyOP
Good Day, I've been trying to figure out how to do ISR on a dynamic segment with the newer app dir stuff and not seeing it. We have 1000's of pages and I don't want to generate those up front but when a user initially visits them?
Answered by Japanese anchovy
Yea, I think we figured it out. For anyone else looking for this answer. You can use:
Then when the route renders it will generate the pages it needs
export async function generateStaticParams() {
return [];
};Then when the route renders it will generate the pages it needs
10 Replies
You can do this in your page.tsx
export const revalidate = 60 // revalidate this page every 60 secondsJapanese anchovyOP
When I build the site it still shows as SSR though and I don't see any static file in the .next directory
are you exporting as static?
app dir is mostly SSR, but you can set longer revalidate periods if the pages don't update often.
to keep the cache
Japanese anchovyOP
Yea, I think we figured it out. For anyone else looking for this answer. You can use:
Then when the route renders it will generate the pages it needs
export async function generateStaticParams() {
return [];
};Then when the route renders it will generate the pages it needs
Answer
@Japanese anchovy Yea, I think we figured it out. For anyone else looking for this answer. You can use:
export async function generateStaticParams() {
return [];
};
Then when the route renders it will generate the pages it needs
I also did the same thing for the app I am currently working on. But looks like this is post is from 2023. Is there a better way to do this in 2024?
because thats how ISR works