prismicio / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
17 stars 14 forks source link

Is there a way of Generating/Using a custom index page? #43

Closed jodiedoubleday closed 4 years ago

jodiedoubleday commented 4 years ago

I have 1 custom type in Prismic I want to use for all page types.

If I set the UID in Prismic to be index, localhost:9000/index works fine but localhost:9000/ (I actually get a flash of the page I want, then a white screen).

I've tried

{
  type: 'Page',
  match: '/',
  previewPath: '/:uid/',
  filter: data => data.node._meta.uid.includes('index'),
  component: require.resolve('./src/templates/page.jsx'),
}

which doesn't work. Has anyone got any suggestions on how to get this?

struckm commented 4 years ago

Can you provide your linkResolver code.

mrseanbaines commented 4 years ago

I don't think you can use variables like :uid in the previewPath property. Maybe try this?

{
  type: 'Page',
  match: '/:uid/',
  filter: data => data.node._meta.uid.includes('index'),
  component: require.resolve('./src/templates/page.jsx'),
}
jodiedoubleday commented 4 years ago

@struckm

exports.linkResolver = function linkResolver(doc) {
  if (doc.type === 'blogpost') return '/blog/' + doc.uid;
  if (doc.uid === 'index') return '/';
  return '/' + doc.uid;
}
jodiedoubleday commented 4 years ago

@mrseanbaines I've removed the preview path but I think have the same issue. I have a Prismic type Page with UID of Index, which just results in a white screen on the root '/' but /index/ works fine. I need this Prismic generated page to replace pages/index.js

jodiedoubleday commented 4 years ago

I think I have found the issue, generally using, I was using previewPath in a different part of the plugin which was set to '/' which was causing duplicate routes