【问题标题】:Nuxt.js: `npm run generate` fails to generate `index.html`Nuxt.js:`npm run generate` 无法生成`index.html`
【发布时间】:2021-03-28 12:34:33
【问题描述】:

生成所有静态路由和动态路由,但不生成index.html。为什么不呢?

nuxt-config.js 我有:

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
}

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    您必须编辑您的dynamicRoutes 函数以在您的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
    }
    

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

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 2021-03-12
      • 2022-08-05
      • 2021-07-02
      • 2021-12-23
      相关资源
      最近更新 更多