防止Get -Statatic Paths运行特定语言环境
您是否有可能防止Next.js Getstatic Paths
用于为特定语言环境生成静态页面?
在我的下一个配置中:
i18n: {
locales: ['default', 'en', 'hu', 'de', 'cz', 'eu', 'sl'],
defaultLocale: 'default',
localeDetection: true,
},
这仅仅是因为我们一直都需要语言环境,并且默认情况下,Next.js不支持它,因此我们必须使用中间件技巧,然后是官方的Next.js文档: https://github.com/github.com/vercel/vercel/next.js/discussions/18419
现在我想生成站点,我不想生成诸如
- /默认/products/id1
- /default/default/products/id2
之类的页面,我该如何防止下一步。因为这行不通:
对于我的常见问题页面,其中/help/[main category]/[sub category]/[help]
。
使用 slice
(我会跳过默认的语言环境):
locales.slice(1).map((locale) => {
pages.map((item) => {
item.data.mainTabList?.[locale]?.map((main, mainidx) => {
main.subTabList?.map((sub, subidx) => {
questions.map((help) => {
help.data.helplist?.[locale]?.map((title) => {
const urllink = {
maincategory: urlConverter(main.tab),
subcategory: urlConverter(sub.tab),
help: title.url
}
routes.push(urllink)
})
})
})
})
})
})
const paths = routes.map((doc) => ({
params: {
maincategory: `${doc.maincategory}`,
subcategory: `${doc.subcategory}`,
help: doc.help?.toLowerCase(),
},
}))
任何人都可以帮助我解决这个问题吗?对于我的网站前缀,我们不会在任何地方使用它。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以控制哪些Locales
GetStatic Paths
将通过返回Paths
array中的所需erentes来生成路径。来自
在您的情况下,您的
getstaticpaths
功能应大致看起来像以下内容。It's possible to control which locales
getStaticPaths
will generate paths for by returning the desired locales in thepaths
array.From the i18n Dynamic Routing documentation:
In your case, your
getStaticPaths
function should roughly look like the following.来自官方:
From the official documentation about getStaticProps: