API无法使用Nuxt处理“ npm run generate”动态路由

时间:2018-10-25 12:46:08

标签: javascript vue.js nuxt.js contentful netlify

运行npm run generate时,Contentful API通常会失败。我不确定这是由于它们无法处理负载还是由于我的生成脚本导致动态路由无法执行。奇怪的是,直到几天前它都可以正常工作。

生成功能以构建动态路线

generate: {
routes: async function() {
  const productModelNumbers = await client.getEntries({
    content_type: "products"
  })

  const accessoryModelNumbers = await client.getEntries({
    content_type: "accessories"
  })

  const categories = await client.getEntries({
    content_type: "category"
  })

  const productRoutes = productModelNumbers.items.map(product => {
    return {
      route: `products/${product.fields.category.fields.slug}/${product.fields.modelNumber}`,
      payload: product
    }
  })

  const accessoryCategories = categories.items.map(category => {
    return {
      route: `accessories/${category.fields.slug}`,
      payload: category
    }
  })

  const accessoryRoutes = accessoryModelNumbers.items.map(accessory => {
    return {
      route: `accessories/${accessory.fields.category.fields.slug}/${accessory.fields.modelNumber}`,
      payload: accessory
    }
  })

  return [...productRoutes, ...accessoryRoutes, ...accessoryCategories]
}
}

错误 enter image description here

任何见解都会受到赞赏

0 个答案:

没有答案