Open scottlyttle opened 5 years ago
You need to configure the link resolver to redirect to the correct page.
If you have a blog post on /blog/foobar, the link resolver should check for the type and uid and redirect to the correct page.
What did you expect to happen?
I'm using the createPage function to generate pages when Gatsby is run, so if the page is unpublished in Prismic the path is never generated. Even when the correct link resolver is set (/${doc.uid}
on my particular site) it will still redirect to the homepage.
Gotcha.
What I've done before is to create like a single page that serves as a "catch-all" page for previews where link resolver cannot find the correct page (unpublished, drafts, etc)
This page finds the most relevant page to use as a template for the preview and replaces the id of the template page with the previewable id.
Massive hack, but yeah I haven't figured this out yet in gatsby land.
I've tried to set-up this plugin however I think I am doing something wrong.
This is my gatsby-config.js:
{
resolve: 'gatsby-plugin-prismic-preview',
options: {
repositoryName: 'test-project', // same as in gatsby-source-prismic
linkResolver(doc) {
console.log('hello, here the link resolver');
console.log(doc);
return `/test`;
},
path: '/preview',
},
},
I don't see any log nor it redirects to /test
@PolGuixe I've found that the example of defining the function inline does not work as you've seen.
Using the require
syntax from the other example, I do get fed to the correct page. Just trying to figure out what is left to get preview content to appear now...
Anyone got this working?
I can't seem to get this plugin working out of the box. The preview button within Prismic correctly redirects to
http://localhost:8000/preview?token=[etc]
(/preview
was set as the link resolver here) but the site eventually redirects back to the homepage athttp://localhost:8000/?token=[etc]
. I understand this may be something related to the linkResolver config for this module and I have tried several options to no avail. In the example folder of this module your link resolver is just'/'
.Do you have any suggestions on how this could be tackled? Is further configuration required?