I am having some problems while generating dynamic routes for Nuxtjs. I have a list of products that I retrieve from the API and I am generating single pages for them.
Everything works flawlessly for the default locale (I am using Nuxt i18n).
The problem is, that I want to call a different API if in another locale. I have tried many things to get the current locale into the routes() method but without any luck.
My code is:
generate: {
target: "static",
crawler: true,
routes: function () {
/* I WANT TO GET CURRENT LOCALE HERE FROM i18n
so that I can call the correct API endpoint */
let products = axios.get('https://example.com/v1/get-products').then((res) => {
return res.data.map(product => {
return {
route: '/product/' + product.slug,
name: 'product',
payload: product
}
})
})
return Promise.all([products]).then(values => {
return [...values[0]]
})
}
}