Next.js Discord

Discord Forum

How to generate SSG in next 14 with app router

Answered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
I have some pages, which fetches data from database. The database data doesn't change. I am using server components. So how do I implement SSG here.
#help-forum
Answered by joulev
you are already doing that. everything is already static.
View full answer

19 Replies

Asiatic LionOP
@joulev but unfortunately I don't have default static rendering. I am fetching data from strapi database. It takes a lot of time to switch between pages and shows the loading page UI.
Asiatic LionOP
import { getData } from "@/lib/getData"; const About = async () => { const data = await getData(); return ( <> {data.map((item) => { return (...); })} </> ); }; export default About;

@joulev this is the about page code. I am fetching some images and data which is shown here. When I navigate to home to "/about" page it takes a lot of time. If it was SSG I believe it would be instantaneous. For time delay I added a loading state.
Asiatic LionOP
@joulev prod anything I am missing so the SSG not working ?
@Asiatic Lion <@484037068239142956> prod anything I am missing so the SSG not working ?
do you use auth in your app or something like that?
@joulev do you use auth in your app or something like that?
Asiatic LionOP
No no. I will create a sandbox and share here later. If you could help.
sure, do share
English Lop
On static and dynamic routes just using
generateStaticParams() { return [] }
will enable SSG.
If you want to prerender the dynamic routes at build time then you'll have to pass the slugs also, like
export async function generateStaticParams() { const posts = await fetch('https://.../posts').then((res) => res.json()) return posts.map((post) => ({ slug: post.slug, })) }
You can verify this by checking X-Nextjs-Cache: response headers.
@joulev sure, do share
Asiatic LionOP
Hey @joulev Sorry for late response, I am sharing the repo and url as well please do see

https://ssg-my-app.vercel.app/

https://github.com/joseph-9900/ssg-my-app
Do this means already the pages are in static ? Then when is the use of generateStaticParams()
@Asiatic Lion Do this means already the pages are in static ? Then when is the use of `generateStaticParams()`
yes they are all already static. the app you posted above is fully static as expected
@Asiatic Lion Do this means already the pages are in static ? Then when is the use of `generateStaticParams()`
generateStaticParams() is when you use a dynamic segment, like app/[foo]/page.tsx
@joulev yes they are all already static. the app you posted above is fully static as expected
Asiatic LionOP
I jst added the api to check. How can I change this to static. And how to change the static to SSG. I saw in pages router it's being done.
Saw this in an youtube video using pages router. How to achieve the SSG on app router.
@Asiatic Lion I jst added the api to check. How can I change this to static. And how to change the static to SSG. I saw in pages router it's being done.
POST route handlers cannot be static. they are supposed to be run every request since they depend on the request.
@Asiatic Lion Saw this in an youtube video using pages router. How to achieve the SSG on app router.
you are already doing that. everything is already static.
Answer
Asiatic LionOP
Ohhh thankyou so much ❤️