I am trying to get gatsby to work with dynamic routes with multiple url parameters. I want to be able to navigate to:
.../items/124/MyItemsTitle
In my gatsby-node.js i have the following code:
exports.onCreatePage = async ({ page, actions }) => {
const { createPage } = actions;
// page.matchPath is a special key that's used for matching pages
// only on the client.
if (page.path.match(/^\/user/)) {
page.matchPath = "/user/*";
// Update the page.
createPage(page);
}
if (page.path.match(/^\/items\/([0-9]+)\/\w+$/)) {
page.matchPath = "/items/:itemId/:itemTitle";
// Update the page.
createPage(page);
}
};
The component for the router is as follows:
items.js
<Router>
<ItemDetail path="/items/:itemId/:itemTitle" />
</Router>
But it just renders out to the 404
I have tried every type of regex available read through the docs multiple times, but always end up with only one variable in the url. then it works. The soon as I use multiple parameters, it breaks.
Thanks!