nuxt: Payload undefined when navigating to page with nuxt-link
In my nuxt.config.js, I have:
generate: {
routes: function () {
return axios.get('https://someapi.com/api/produkter').then(function (res) {
const produkter = res.data.map(el => el.fields)
return [{
route: '/produkter/anledninger/jul',
payload: produkter
}]
})
}
},
In my page (pages/produkter/anledninger/_id.vue), I have:
async asyncData ({ params, error, payload }) {
console.log('payload', payload)
return {
produkter: payload
}
}
Generating static site with nuxt generate. When I navigate to this page via a nuxt-link, payload is undefined. Upon refresh (or navigating via < a>), payload is populated with the data.
Using nuxt 1.0.0-rc11.
<div align="right">This question is available on Nuxt.js community (#c1904)</div>About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 18
I am also having the same problem in nuxt 1.4.0.
I came up with a similar solution. I hook into the generate function and cache the API responses locally:
https://github.com/scottsweb/scott.ee/blob/master/modules/generate.js
Then in production I modify the axios URLs to point at the locally cached JSON:
https://github.com/scottsweb/scott.ee/blob/master/plugins/axios.js#L1-L28