问题
When I run nuxt generate
with target: "static"
in my nuxt.config.js
, my dynamically-created routes do not accept their payload, which they get like so:
****nuxt.config.js****
generate: {
routes() {
return axios
.get(`${process.env.ROOT_URL}/businesses`)
.then(res => {
return res.data.map(business => {
return {
route: `/business/${business.id}`,
payload: business
};
});
});
}
}
****business.vue****
async asyncData({ params, store, error, payload }) {
if (payload) {
console.log('GOT PAYLOAD!', payload);
return { business: payload };
} else {
// other stuff
}
})
During nuxt generate
the console.log above is hit for each dynamic route, so I know it's receiving its correct payload.
After nuxt generate
my dist
folder has a subfolder for each dynamic route, but the index.html
for each has only a few lines inside , and when I visit the page for each on the browser no content specific to the dynamic route appears (the navbar from my layout
component comes up fine).
Navigation in app works fine, so if I go to a different page and come page to my dynamic route content will appear, so asyncData
works, accepting the payload is the trouble.
Without target: "static"
things work as expected, the index.html
for each in dist
has plenty in it, and the page loads the desired content when visited, although the head()
method in business.vue is not generated (see my question about that here).
Can anyone point out what I'm missing/doing wrong?
来源:https://stackoverflow.com/questions/64148659/nuxtjs-dynamic-routes-not-accepting-payload-when-full-static