gatsby-starter-prismic
gatsby-starter-prismic copied to clipboard
Pages linked from Category template don't exist
I currently have one Category
set up on Prismic, which a couple articles linked. The build process is successful. However, when I click to the category page and then on the article links (relative path: /categories/category-slug
/article-slug
), I get the following error message on Netlify:
Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site.
During local dev, I get the following message:
Create a React.js component in your site directory at src/pages/categories/category-slug
/page-slug
and this page will automatically refresh to show the new page component you created.
Is there a configuration step that's missing from the README, or do these links paths need to be adjusted on the category page template?
For anyone else having this problem, I solved this by adding a new createPage
action inside of the postsList
loop in gatsby-node.js
to generate the missing routes.
if (edge.node.data.categories[0].category) {
edge.node.data.categories.forEach((cat) => {
const categoryName = cat.category.document[0].data.name
const categorySlug = `${_.kebabCase(categoryName)}`
categorySet.add(categoryName)
createPage({
path: `/categories/${categorySlug}/${edge.node.uid}`,
component: postTemplate,
context: {
// Pass the unique ID (uid) through context so the template can filter by it
uid: edge.node.uid,
},
})
})
}