最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - How to use 'generateStaticParams' for nested route in Next.js 15 - Stack Overflow

programmeradmin3浏览0评论

I have the following folder structure in my Next.js 15 app:

• app
    ◦ layout.tsx
    ◦ page.tsx
    ◦ [lang]
        ▪ [...slug]
            • page.tsx

How and where should I use 'generateStaticParams' to get prerendered content for the following URLs:

  • /en/blog/post-1
  • /de/blog/post-1
  • /en/contact
  • /de

I have the following folder structure in my Next.js 15 app:

• app
    ◦ layout.tsx
    ◦ page.tsx
    ◦ [lang]
        ▪ [...slug]
            • page.tsx

How and where should I use 'generateStaticParams' to get prerendered content for the following URLs:

  • /en/blog/post-1
  • /de/blog/post-1
  • /en/contact
  • /de
Share Improve this question asked 2 days ago TomaszTomasz 551 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

According to the docs, using multiple dynamic segments + catch-all dynamic segments, this should be the output:

// /[lang]/[[...slug]]/page.tsx
export function generateStaticParams() {
  return [
    { lang: 'en', slug: ['blog', 'post-1'] },
    { lang: 'de', slug: ['blog', 'post-1'] },
    { lang: 'en', slug: ['contact'] },
    { lang: 'de', slug: undefined } /* Because catch-all route is optional you can do this*/

  ]
}

However make sure that [...slug] becomes [[...slug]] (optional catch-all segment) You can read more about it here

发布评论

评论列表(0)

  1. 暂无评论