I want to static generate my dynamic route so there won't be api requests on the deployed site. However I seem to be doing something wrong since my asyncData method is always skipping to the "else" condition.
In my nuxt.config.js
const axios = require('axios')
module.exports = {
generate: {
routes: function () {
return axios.get('http://exmaple.com/api/cases')
.then((res) => {
return res.data.objects.map((content) => {
return {
route: '/case/' + content.slug,
payload: content
}
})
})
}
}
}
And in my dynamic page/route component
export default {
async asyncData ({ params, error, payload }) {
if (payload) return { content: payload }
else return {
content: 'something else'
}
}
}
It is always skipping to "something else", both before and after nuxt generate has been completed. From my understanding, the else return should be returned during dev "npm run dev", else the payload from routes generate should be returned?
EDIT: is it possible to generate a 100% static site and decouple the API?
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1731">#c1731</a>)</em></sub></div>