Hi,
I have read all posts related to this issue and can't find an answer anywhere. We have previews working for published documents but we are getting a 404 for all unpublished documents. I am struggling with debugging it. Any help would be appreciated.
We are using:
gatsby: 5.11.0
gatsby-source-prismic: 6.0.0
gatsby-plugin-prismic-previews: 6.0.0
react: 18.2.0
Our relevant files:
404.js
import * as React from 'react'
import {withPrismicUnpublishedPreview} from 'gatsby-plugin-prismic-previews'
const NotFoundPage = () => {
return (
<div>
<h1>Not found</h1>
</div>
)
}
export default withPrismicUnpublishedPreview(NotFoundPage);
gatsby-browser.js and gatsby-ssr.js
import * as React from "react";
import {
PrismicPreviewProvider,
} from "gatsby-plugin-prismic-previews";
import linkResolver from "./src/utils/linkResolver";
import {lazy} from "react";
const repositoryConfigs = [
{
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
linkResolver,
componentResolver: {
project: lazy(() => import('./src/templates/ProjectPage')),
story: lazy(() => import('./src/templates/StoryPage')),
homepage: lazy(() => import('./src/templates/HomePage')),
practice: lazy(() => import('./src/templates/PracticePage')),
person: lazy(() => import('./src/templates/PersonPage')),
employment: lazy(() => import('./src/templates/EmploymentPage')),
},
},
]
export const wrapRootElement = ({element}) => (
<PrismicPreviewProvider repositoryConfigs={repositoryConfigs}>
{element}
</PrismicPreviewProvider>
);
gatsby-config.js
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
});
const linkResolver = require("./src/utils/linkResolver");
const routes = [
{
type: 'project',
path: '/:lang/work/:uid',
},
{
type: 'story',
path: '/:lang/stories/:uid',
},
{
type: 'homepage',
path: '/:lang',
},
{
type: 'practice',
path: '/:lang/practice',
},
{
type: 'person',
path: '/:lang/people/:uid',
},
{
type: 'employment',
path: '/:lang/employment',
},
]
module.exports = {
flags: {
DEV_SSR: false,
},
plugins: [
{
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,
routes: routes,
},
},
{
resolve: "gatsby-plugin-prismic-previews",
options: {
repositoryName: process.env.GATSBY_PRISMIC_REPO_NAME,
accessToken: process.env.PRISMIC_ACCESS_TOKEN,
linkResolver,
routes: routes,
},
},
],
};
link-resolver.js
const linkResolver = (doc) => {
// Pretty URLs for known types
if (doc.type === "project") return `/${doc.lang}/work/${doc.uid}`;
if (doc.type === "story") return `/${doc.lang}/stories/${doc.uid}`;
if (doc.type === "person") return `/${doc.lang}/people/${doc.uid}`;
if (doc.type === "homepage") return `/${doc.lang}`;
if (doc.type === "employment") return `/${doc.lang}/employment`;
if (doc.type === "practice") return `/${doc.lang}/practice`;
// Backup for all other types
return `/${doc.lang}`;
};
module.exports = linkResolver;
I feel like I have tried every combination of setup from every one of the related posts in this community as well as all the various documentation articles. Banging my head against a brick wall on this one.