Next.js Discord

Discord Forum

Static generation of html - CONFUSED

Answered
Oak apple gall wasp posted this in #help-forum
Open in Discord
Oak apple gall waspOP
Guys I am little bit confused, as I know
generateStaticParams
creates static routes which makes me think that htmls should be statically generated, but when I build my app I don't see any HTML being generated, could u please explain how it exactly works?

export const dynamicParams = true;

export async function generateStaticParams() {
  const posts = await fetch("https://jsonplaceholder.typicode.com/posts").then((res) => res.json());

  return posts;
}

export default async function Page({ params }: { params: { id: string } }) {
  const { id } = params;

  const post = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`).then((res) =>
    res.json(),
  );

  if (!post) {
    return <div>Post not found</div>;
  }

  return <div className="flex w-full justify-center py-2">{JSON.stringify(post)}</div>;
}

22 Replies

Oak apple gall waspOP
Next config is default one
Didn’t change anything
I am also expecting some dynamic routes during post creation but egenrally
Ok build I want to create staric pages which is available on build time
In DB
Answer
@Oak apple gall wasp In DB
I didn't get wym
Oak apple gall waspOP
When I run npm run build I don’t see generated htmls in .next folder
during build. however, it won't be in html
You can get output in folder like static
Oak apple gall waspOP
Is there a diff between static params and static pages in next?
Static Params are generally used in static routes
All pages are generated at build time
Oak apple gall waspOP
When you say generated wdy exactly by that? Because I don’t see any static conent for my 20 posts lets say
@Oak apple gall wasp resolved?
Oak apple gall waspOP
yes