drake035
drake035

Reputation: 2897

Nuxt.js: `npm run generate` fails to generate `index.html`

All static routes and dynamic routes are generated, but not index.html. Why not?

In nuxt-config.js I have:

const staticRoutes =
  [
    '/about',
    '/contact',
    '/portfolio'
  ]
const dynamicRoutes = async () => {
  const routes = await axios.get('https://my-site.com/wp/wp-json/projects/v1/posts')
    .then(res => res.data.map((project) => `/project/${project.ID}/${project.post_name}`))

  return routes
}

Upvotes: 1

Views: 578

Answers (1)

Nicolas Pennec
Nicolas Pennec

Reputation: 7631

You have to edit your dynamicRoutes function to add the index / route in your routes:

const dynamicRoutes = async () => {
  const routes = await axios.get('https://fabricepallaud.com/wp/wp-json/projects/v1/posts')
    .then(res => res.data.map((project) => `/project/${project.ID}/${project.post_name}`))

  routes.push("/")

  return routes
}

see https://github.com/nuxt-community/router-module#using-top-level-options

Upvotes: 1

Related Questions