I want to generate both static routes (/contact, /about, ...) and dynamic routes (/project/1, /project/2, ...) for my project, so that when user refreshes the page while visiting any of these routes, the page still works.
But when doing npm run generate I only get Generated route "/" and in /dist folder I see no routes generated.
Nuxt.js version used: 2.14.7
I tried with both universal and spa modes, it works with neither.
In nuxt.config.js I have at the top:
const axios = require('axios')
const dynamicRoutes = async () => {
const routes = await axios.get('http://my-project.com/wp/wp-json/projects/v1/posts')
.then(res => res.data.map((project) => `/project/${project.ID}/${project.post_name}`))
.then(res => res.concat(
[
'/about',
'/contact',
'/portfolio'
]
))
return routes
}
Then in export default {}:
generate: {
routes: dynamicRoutes
},