fix(next): adjusts args sent through live preview url

This commit is contained in:
Jacob Fletcher
2024-04-05 12:18:40 -04:00
parent 91f9973c6c
commit 1b6026304f
4 changed files with 34 additions and 8 deletions

View File

@@ -1,4 +1,9 @@
export const formatLivePreviewURL = async ({ data, documentInfo }) => {
import type { LivePreviewConfig } from 'payload/config'
export const formatLivePreviewURL: LivePreviewConfig['url'] = async ({
data,
collectionConfig,
}) => {
let baseURL = 'http://localhost:3000/live-preview'
// You can run async requests here, if needed
@@ -21,6 +26,6 @@ export const formatLivePreviewURL = async ({ data, documentInfo }) => {
// I.e. append '/posts' to the URL if the document is a post
// You can also do this on individual collection or global config, if preferred
return `${baseURL}${
documentInfo?.slug && documentInfo.slug !== 'pages' ? `/${documentInfo.slug}` : ''
collectionConfig && collectionConfig.slug !== 'pages' ? `/${collectionConfig.slug}` : ''
}${data?.slug && data.slug !== 'home' ? `/${data.slug}` : ''}`
}