Is there a way to prevent Next.js getStaticPaths
from generating static pages for a specific locale?
In my Next.js configuration:
i18n: {
locales: ['default', 'en', 'hu', 'de', 'cz', 'eu', 'sl'],
defaultLocale: 'default',
localeDetection: true,
},
We always need the locale, which is not supported by Next.js by default. To work around this, we have to use the middleware trick as described in the official Next.js documentation: https://github.com/vercel/next.js/discussions/18419
However, I do not want Next.js to generate pages like:
- /default/products/id1
- /default/products/id2
How can I prevent this behavior? The current method I tried with slice
is not working:
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(),
},
}))
I need help in finding a solution to prevent the generation of /default
pages, as this is just a workaround for my locale prefix and will not be used anywhere.