gatsby-starter-prismic icon indicating copy to clipboard operation
gatsby-starter-prismic copied to clipboard

Pages linked from Category template don't exist

Open gcamacho079 opened this issue 4 years ago • 1 comments

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?

gcamacho079 avatar Sep 04 '20 01:09 gcamacho079

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,
          },
        })
      })
    }

gcamacho079 avatar Oct 09 '20 14:10 gcamacho079