1
createPage({
    path: `product/${node.id}/[any-matching-string]`,
    component: path.resolve(`./src/templates/productDetail.js`),
    context: {
      productId: node.id
    },
  })

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

How do i achieve such path?
url: someurl/product/id/[any string]

Mahesh
  • 1,503
  • 3
  • 22
  • 33
  • 2
    Do you want to create a dynamic route at `product`? https://stackoverflow.com/questions/55756994/how-to-create-dynamic-route-in-gatsby – ksav Sep 09 '19 at 06:32
  • Possible duplicate of [How to create dynamic route in gatsby](https://stackoverflow.com/questions/55756994/how-to-create-dynamic-route-in-gatsby) – EliteRaceElephant Sep 09 '19 at 06:52

1 Answers1

1

Yes.According to those two comments, it is possible duplicate of those questions. But i slightly wanted different settings.

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

This is what i exactly wanted.

And in my index.js page, i have to use reach router.
If anyone need more details, comment here. I will share the complete code.

Mahesh
  • 1,503
  • 3
  • 22
  • 33
  • Doesn't this kind of defeat the purpose of using gatsby? – ksav Sep 09 '19 at 18:00
  • How? I will not accept my answer if there is a problem on this. I actually discussed with Gatsby team on github. I did not get any objection from them. Can you explain a little more about the problem in using this? – Mahesh Sep 11 '19 at 10:35