I am currently working with a headless WordPress site in Next.js. I struggle a bit with the routing for internationalization. I have 2 main page files relevant for this question:
pages/[...slug].tsx
In this file I use a getStaticPaths function to fetch GraphQL data for all pages in my WordPress database.
pages/[locale]/Blog/[...slug].tsx
In this file I use a getStaticPaths function to fetch GraphQL data for all blog posts in my WordPress database.
I have locales configured in my next.config file like this:
i18n: {
locales: ['da-DK', 'en-GB'],
defaultLocale: 'da-DK',
},
I struggle to find a way to catch all the blog posts. With my current file structure, I will catch all blog posts with an url like:
siteName/en/blog/page-name
BUT not blog posts under default language with the structure:
siteName/blog/page-name
I tried with [[locale]] but got the error:
Error: Optional route parameters are not yet supported ("[[locale]]").
so only catch-all routes can be made optional it seems. Any idea how to handle something like this? Another way could be to 'join' the 2 different files for posts and blog posts and then use some conditional logic to sort if I need a Query for a post or a page. I would rather avoid this if possible...