如何在gatsbyJS中动态创建带有参数的页面?

时间:2020-05-23 05:44:56

标签: gatsby

我想要一条类似/blog/:blogId/:slug

的路线

我在gatsby-node.js-

中尝试过
exports.onCreatePage = async ({ page, actions }) => {
  const { createPage } = actions

  createPage({
      path: "/blog/",
      matchPath: "/blog/:blogId/:slug",
      component: path.resolve("src/components/layouts/SingleBlogPageLayout.jsx"),
  })
}

它在gatsby develop中可以正常工作,但在gatsby build中显示问题

错误是:

failed Building static HTML for pages - 6.584s

 ERROR #95313 

Building static HTML failed for path "/"

See our docs page for more info on this error: https://gatsby.dev/debug-html


  247 | 
  248 | 
> 249 |       var store = didStoreComeFromProps ? props.store : contextValue.store;
      | ^
  250 |       var childPropsSelector = useMemo(function () {
  251 |         // The child props selector needs the store reference as an input.
  252 |         // Re-create this selector whenever the store changes.


  WebpackError: TypeError: Cannot read property 'store' of null

  - connectAdvanced.js:249 ConnectFunction
    node_modules/react-redux/es/components/connectAdvanced.js:249:1

1 个答案:

答案 0 :(得分:3)

gatsby-browser.jsgatsby-ssr.js文件中添加redux包装器

Import wrapWithProvider from "./wrap-with-provider"

export const wrapRootElement = wrapWithProvider

希望这行得通