【问题标题】:Why getStaticProps is not getting correct slug?为什么 getStaticProps 没有得到正确的 slug?
【发布时间】:2021-06-04 22:36:10
【问题描述】:

我在 getStaticProps() 中获取正确的 slug 时遇到问题。我正在尝试为该页面翻译 slug(例如:关于页面)

getStaticPaths() 生成正确的对象。这些参数来自 DatoCMS API

 [
  { params: { slug: 'about-us' }, locale: 'en' },
  { params: { slug: 'ueber-uns' }, locale: 'de' },
  ...  
]

但是,当我在德语页面 (www.exmaple.com/de/ueber-uns) 上时,getStaticProps 给出的上下文如下。

{
  params: { slug: 'about-us' }, // it should be `ueber-uns` or ?
  locales: [ 'en', 'de' ],
  locale: 'de', // this is correct 
  defaultLocale: 'en'
}

我正在关注这里的文档 -> https://nextjs.org/docs/advanced-features/i18n-routing#dynamic-getstaticprops-pages

【问题讨论】:

    标签: javascript reactjs next.js


    【解决方案1】:

    getStaticPaths 方法仅定义在构建期间应静态生成哪些“页面”。您的问题将是错误的getStaticProps 实现,恕我直言。

    您能否为我们提供getStaticProps 的实施?

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多