Generating pages statically - App Router
Answered
Leafcutting bee posted this in #help-forum
Leafcutting beeOP
Hi all, having a bit of trouble wrapping my head around static page generation using the app router.
### Dynamic Routes
I understand that in a
### Non-dynamic routes
How would I get my
Sorry if I've missed anything obvious, thanks for reading.
### Dynamic Routes
I understand that in a
app/[slug]/page.tsx file I can include a generateStaticParams function, this should return an array like [{slug: "slug1"}, {slug: "slug2"}]. My confusion is where I should do my data fetching for this. Should I still do my data fetching within the server component or should I do my data fetching in my generateStaticParams function and have a content property on each object in the array?### Non-dynamic routes
How would I get my
app/page.tsx page to statically render? Do I still need to return an array of slugs from the generateStaticParams function?Sorry if I've missed anything obvious, thanks for reading.
Answered by joulev
dynamic pages != dynamic param pages.
dynamic param pages that are statically generated (via
dynamic param pages that are statically generated (via
generateStaticParams) are still static pages12 Replies
@Leafcutting bee Hi all, having a bit of trouble wrapping my head around static page generation using the app router.
### Dynamic Routes
I understand that in a `app/[slug]/page.tsx` file I can include a `generateStaticParams` function, this should return an array like `[{slug: "slug1"}, {slug: "slug2"}]`. My confusion is where I should do my data fetching for this. Should I still do my data fetching within the server component or should I do my data fetching in my `generateStaticParams` function and have a `content` property on each object in the array?
### Non-dynamic routes
How would I get my `app/page.tsx` page to statically render? Do I still need to return an array of slugs from the `generateStaticParams` function?
Sorry if I've missed anything obvious, thanks for reading.
dynamic routes: you should do it inside the server component. you cannot pass any data from
non-dynamic routes: it statically renders by default, you don't need to do anything. you can force it to statically render (or throw an error if it can't do so) by using
generateStaticParams to the server component, other than the slugnon-dynamic routes: it statically renders by default, you don't need to do anything. you can force it to statically render (or throw an error if it can't do so) by using
export const dynamic = "error"@joulev dynamic routes: you should do it inside the server component. you cannot pass any data from `generateStaticParams` to the server component, other than the slug
non-dynamic routes: it statically renders by default, you don't need to do anything. you can *force* it to statically render (or throw an error if it can't do so) by using `export const dynamic = "error"`
Leafcutting beeOP
Awesome, thank you! Is there any way to configure a revalidation time in the App router?
@Leafcutting bee Awesome, thank you! Is there any way to configure a revalidation time in the App router?
export const revalidate = 10 if you want to revalidate every 10 seconds@joulev `export const revalidate = 10` if you want to revalidate every 10 seconds
Leafcutting beeOP
Thank you so much
@joulev `export const revalidate = 10` if you want to revalidate every 10 seconds
Leafcutting beeOP
Sorry, this is for both dynamic and non-dynamic?
@Leafcutting bee Sorry, this is for both dynamic and non-dynamic?
only for static pages. dynamic pages always revalidate. in fact
export const revalidate = 0 is a valid way to make a dynamic page for something that would otherwise be a static page@joulev only for static pages. dynamic pages always revalidate. in fact `export const revalidate = 0` is a valid way to make a dynamic page for something that would otherwise be a static page
Leafcutting beeOP
Oh this is confusing, so a dynamic page will revalidate every time a user visits it?
I'm basically trying to get ISR behaviour on all my dynamic and non-dynamic routes
@Leafcutting bee Oh this is confusing, so a dynamic page will revalidate every time a user visits it?
dynamic pages != dynamic param pages.
dynamic param pages that are statically generated (via
dynamic param pages that are statically generated (via
generateStaticParams) are still static pagesAnswer
that's what i meant
there are two different meanings of "dynamic" here
Leafcutting beeOP
Ahh ok thank you, yeah, got myself confused