Hi there,
I use the preview functionality on a few of our Next.js sites. It works great when the routes are directly accessible. But for some pages, we use middleware to redirect them internally to the right page component. For these pages, the preview doesn't seem to work, especially for pages that haven't been published yet. I'm assuming this is because the previewData that gets passed to the getStaticProps
isn't available to the middleware to be passed to the createClient
function used in our middleware file. Is there a way to get this previewData
in the middleware so the internal routing works?
Quick summary of what we do: based on the slug, we fetch a document that has the slug in a field. This returns null because the page hasn't been published yet, resulting us to return a 404 page.