Using Gatsby File System Route API

I'm having difficulty setting up dynamic pages with the Gatsby File System Route API and Prismic. I created a document called ~/src/pages/{PrismicPage.url}.js. In my Prismic repo, I have 2 'page' types, one called home and one called faq. I also have a link resolver setup up as:

exports.linkResolver = (doc) => {
  // URL for a page type
  if (doc.type === "page") {
    return `/${doc.uid}`;
  }

  // Backup for all other types
  return "/";
};

and in my Gatsby config as:

{
      resolve: "gatsby-source-prismic",
      options: {
        repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
        accessToken: process.env.PRISMIC_ACCESS_TOKEN,
        customTypesApiToken: process.env.PRISMIC_CUSTOM_TYPES_API_TOKEN,
        linkResolver: require("./src/LinkResolver").linkResolver,
      },
    },

When I run gatsby develop, the route that is create is listed as /url}/{PrismicPage/

Not sure what I am doing wrong here.

Hey @mitchelsarauer, thanks for reaching out!

So the URL that gets created is /url}/{PrismicPage/?
Can you show me an example of the entire route?

Your setup seems fine.

The entire route in the browser is http://localhost:8000/url}/{PrismicPage/

  • What's the name of the file inside the /pages folder?
  • Also, does your Page type have a UID field?

The name of the file is {PrismicPage.url}.js.

Ya it has a uid. Here is the JSON of the page type:

{
  "Main" : {
    "uid" : {
      "type" : "UID",
      "config" : {
        "label" : "UID"
      }
    },
    "title" : {
      "type" : "StructuredText",
      "config" : {
        "single" : "heading2",
        "label" : "Title"
      }
    },
    "page_description" : {
      "type" : "StructuredText",
      "config" : {
        "multi" : "paragraph",
        "label" : "Page Description"
      }
    },
    "body" : {
      "type" : "Slices",
      "fieldset" : "Slice zone",
      "config" : {
        "labels" : null,
        "choices" : {
          "faq" : {
            "type" : "Slice",
            "fieldset" : "FAQ",
            "description" : "FAQ Section",
            "icon" : "question_answer",
            "display" : "list",
            "non-repeat" : { },
            "repeat" : {
              "question" : {
                "type" : "StructuredText",
                "config" : {
                  "single" : "heading3",
                  "label" : "Question"
                }
              },
              "answer" : {
                "type" : "StructuredText",
                "config" : {
                  "multi" : "paragraph,hyperlink,list-item,o-list-item",
                  "label" : "Answer"
                }
              }
            }
          },
          "link_cards" : {
            "type" : "Slice",
            "fieldset" : "Link Cards",
            "description" : "Group of Link Cards",
            "icon" : "check_box_outline_blank",
            "display" : "grid",
            "non-repeat" : {
              "section_title" : {
                "type" : "StructuredText",
                "config" : {
                  "single" : "heading3",
                  "label" : "Section title"
                }
              },
              "section_description" : {
                "type" : "StructuredText",
                "config" : {
                  "multi" : "paragraph",
                  "label" : "Section Description"
                }
              }
            },
            "repeat" : {
              "card_title" : {
                "type" : "StructuredText",
                "config" : {
                  "single" : "heading3",
                  "label" : "Card Title"
                }
              },
              "card_text" : {
                "type" : "StructuredText",
                "config" : {
                  "multi" : "paragraph",
                  "label" : "Card Text"
                }
              },
              "link" : {
                "type" : "Text",
                "config" : {
                  "label" : "Link"
                }
              },
              "card_tag" : {
                "type" : "Text",
                "config" : {
                  "label" : "Card Tag"
                }
              },
              "card_tag_color" : {
                "type" : "Select",
                "config" : {
                  "options" : [ "primary", "secondary", "warning" ],
                  "default_value" : "primary",
                  "label" : "Card Tag Color"
                }
              }
            }
          },
          "paragraph_section" : {
            "type" : "Slice",
            "fieldset" : "Paragraph Section",
            "description" : "Paragraph Section",
            "icon" : "description",
            "display" : "list",
            "non-repeat" : {
              "paragraph_title" : {
                "type" : "StructuredText",
                "config" : {
                  "single" : "heading3",
                  "label" : "Paragraph Title"
                }
              },
              "paragraph_text" : {
                "type" : "StructuredText",
                "config" : {
                  "multi" : "paragraph,hyperlink,list-item,o-list-item",
                  "label" : "Paragraph Text"
                }
              }
            },
            "repeat" : { }
          }
        }
      }
    }
  }
}

That's very odd. If you want you can send me the URL of your project (GitHub repo) and I can try and run the project on my machine to see if I can catch the error.