Issue with previewing slug routes in Sanity Studio-embedded previews.
I can see you're running into two issues with the iframe preview setup. Let me address both:
The URL vs url key issue
You're absolutely right - it should be lowercase url: not URL:. This is case-sensitive, and the correct property name in the iframe options object is url. That's why changing it to lowercase made it work.
The path-only URL issue in the iframe
The problem you're experiencing where the iframe shows only /api/preview?slug=/about instead of the full http://localhost:3000/api/preview?slug=/about is likely happening because you have angle brackets in your URL string:
url: (doc) => doc?.slug?.current
? `<http://localhost:3000/api/preview?slug=${doc.slug.current}>`
: `<http://localhost:3000/api/preview>`,Remove the angle brackets - they're not part of the actual URL syntax and are causing the protocol/domain to be stripped. It should be:
url: (doc) => doc?.slug?.current
? `http://localhost:3000/api/preview?slug=${doc.slug.current}`
: `http://localhost:3000/api/preview`,The angle brackets < > are just markdown/documentation formatting that sometimes appears in examples, but they shouldn't be in your actual code.
Modern alternative: Presentation tool
Since you're working on live preview functionality, you might want to check out the Presentation tool which is the modern approach to visual editing in Sanity Studio. It provides a more robust iframe preview experience with built-in support for visual editing features. The guide you're following is for the older Pages Router approach, which still works, but the Presentation tool offers a better developer experience.
If you're still seeing issues after removing the angle brackets, double-check that your preview API route is correctly handling the slug parameter and that doc?.slug?.current actually contains the value you expect when the function runs.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.