【问题标题】:Gatsby createpages dynamic pathGatsby createpages 动态路径
【发布时间】:2020-01-10 14:27:47
【问题描述】:
createPage({
    path: `product/${node.id}/[any-matching-string]`,
    component: path.resolve(`./src/templates/productDetail.js`),
    context: {
      productId: node.id
    },
  })

路径:product/${node.id}/[any-matching-string],

我如何实现这样的路径?
url: someurl/product/id/[任意字符串]

【问题讨论】:

标签: gatsby


【解决方案1】:

是的。根据这两个 cmets,这些问题可能重复。但我有点想要不同的设置。

exports.onCreatePage = async ({ page, actions }) => {
  const { createPage } = actions    
  if (page.path === "/") {
    page.matchPath = "/*"
    createPage(page)
  }
}

这正是我想要的。

在我的 index.js 页面中,我必须使用到达路由器。
如果有人需要更多详细信息,请在此处发表评论。我将分享完整的代码。

【讨论】:

  • 这样不是违背了使用 gatsby 的目的吗?
  • 怎么样?如果这有问题,我不会接受我的回答。我实际上在 github 上与 Gatsby 团队讨论过。我没有得到他们的任何反对。你能解释一下使用这个的问题吗?
猜你喜欢
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 2020-02-29
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
  • 2021-07-25
相关资源
最近更新 更多