2

I feel like I must be missing something or misunderstand something.

I am using generateStaticParams:

export async function generateStaticParams() {
  let blogPosts = await prisma.posts.findMany({
    where: {
        category: "POLITICS",
    },
  });

  const paths = blogPosts.map((text) => ({
      slug: text.slug,
  }));


  return paths
}

I want to only generate static pages only for this route, and return a 404 when a user tries to visit something, that does not exist at build time. So I am opting out of dynamic:

export default MyPage;
export const dynamic = 'force-static'
export const dynamicParams = false;

However, when I build this, this gives me a 404 for all my static routes. It works when I leave things dynamic and also in development, but not when I build the project.

Next.JS also tells me that it recgonised the page and generated a static version:

├ ● /posts/[slug]               0 B                0 B
├   └ /posts/my-static-post
├ ○ /about                      0 B                0 B

But when I visit it in production, it's a 404.

antonwilhelm
  • 5,768
  • 4
  • 19
  • 45
  • 1
    yess, I just wanted to migrate a page type to the app router and I seem to have the exact same problem. At this point I'm wondering whether I'm doing something wrong or is this some kind of bug? – razzz Jun 15 '23 at 04:54
  • 1
    And another interesting thing: If I remove the `dynamicParams=false` setting, it works BUT the pages are being (re)generated on first visit, which kind of defeats the purpose of having them statically generated in the first place. (And yes, they were already generated at build-time, I confirmed it) – razzz Jun 15 '23 at 05:19
  • 2
    I started to make a sandbox but for some reason it's working in the stackblitz, but not in my actual project: https://stackblitz.com/edit/stackblitz-starters-pbid6j?file=app%2Farticles%2F%5Bslug%5D%2Fpage.tsx – razzz Jun 15 '23 at 06:25
  • same issue just now: I want to prevent regeneration of excisting routes to avoid high costs. so i want to staticly generate some paths and let ssr to generate the future ones, but d'ont know how! – Miftah Classifieds Aug 06 '23 at 10:50
  • Maybe it can help, I had the same problem and when I was using "use client", the dynamicParams = false didn't work, but when I removed "use client", it worked correctly again. I'm not sure how to deal with cases where you need the page to be a client component. – Kevin Kirsten Lucas Aug 31 '23 at 23:47

0 Answers0