Hi there,
I have setup previews for a site built in NextJS, however previews are only working for the master locale.
When previewing a non master locale, I get the error No documents were returned
. This error is returned from client.resolvePreviewURL
. Even though ref
and documentId
have the expected values.
Preview file:
const preview = async (req, res) => {
const { token: ref, documentId } = req.query;
const redirectUrl = await client.resolvePreviewURL({
linkResolver,
defaultURL: '/',
previewToken: ref,
documentID: documentId,
});
if (!redirectUrl) {
return res.status(401).json({ message: 'Invalid token' });
}
res.setPreviewData({ ref });
res.write(
`<!DOCTYPE html><html><head><meta http-equiv="Refresh" content="0; url=${redirectUrl}" />
<script>window.location.href = '${redirectUrl}'</script>
</head>`
);
res.end();
};
Link resolver:
export const linkResolver = (document) => {
const lang = getLocaleByLanguage(document.lang);
switch (document.type) {
case 'blog_post':
return `/${lang}/blog/${document.data.category.uid}/${document.uid}`;
case 'blog_category':
return `/${lang}/blog/${document.uid}`;
case 'page_blog':
return `/${lang}/blog`;
default:
return '/';
}
};
package.json
"@prismicio/client": "^6.0.0",
"next": "12.0.7",
Any help or advice would be appreciated
Thanks,
Sarah