Create Studio edit intent links
Learn how to construct URLs that open specific documents and fields in Sanity Studio for custom editorial interfaces and preview environments.
Edit intent links are URLs that open specific documents and fields in Sanity Studio. They are useful for building custom editorial interfaces or adding edit buttons to your preview environments.
When combined with Content Source Maps or steganography, you can automatically generate these URLs based on source map data for fully automated visual editing experiences. This article covers the manual approach for cases where you need direct control over the links. The resolveEditUrl helper covers the automatic approach, for cases where you have a Content Source Map but not the document ID.
Edit intent URL format
The basic format for an edit intent URL is:
<your-studio-url>/intent/edit/id=DOCUMENT_ID;type=DOCUMENT_TYPE;path=FIELD_PATH<your-studio-url> includes the workspace base path, for example https://example.sanity.studio/production for a workspace with basePath: '/production'. Put the parameters in one path segment, separated by ;, and encode each value with encodeURIComponent.
The URL takes these parameters:
idis the published document ID, without adrafts.orversions.prefix. To open a version in a release, add?perspective=RELEASE_IDto the URL.typeis the document type. Without it, the studio has to look up the document before the Structure Tool can open it, and the Presentation Tool can't open it at all.pathis the field to focus. Encode it withencodeURIComponent: the studio splits each parameter on=, so an unencodedbody[_key=="a1b2c3"]is cut short atbody[_keyand the link doesn't focus the field you asked for. Leavepathout to open the document at the top.
Field path syntax
The path uses the string format of Studio form paths. Dots separate nested fields, and _key selects an array item:
seo.metaTitlefocuses a field inside an object.sections[_key=="a1b2c3"].headingfocuses a field inside an array item.body[_key=="blk1"]focuses a block in a Portable Text field.
Index selectors such as gallery[2].alt also work, and the studio converts them to keys when the document opens. A key keeps pointing at the same item after the array is reordered, so use keys for links that you store or send.
The studio scrolls to the field and focuses it. If the field is in a field group that isn't selected, in a collapsed fieldset, or in a nested object, the studio opens those first.
Open an inspector or a release
Add these parameters to the same path segment as id and type:
inspect=sanity/structure/historyopens the document's history.inspect=sanity/structure/validationopens the validation panel.inspect=sanity/structure/incoming-referencesopens the documents that reference this one.inspect=sanity/commentsopens comments. Addcomment=COMMENT_IDto select a comment thread.view=VIEW_IDopens a document view defined withS.document().views().
To open a version in a release, add ?perspective=RELEASE_ID after the path segment. ?perspective=published opens the published version.
<your-studio-url>/intent/edit/id=page-home;type=page;path=sections%5B_key%3D%3D%22a1b2c3%22%5D.heading;inspect=sanity%2Fstructure%2Fhistory?perspective=RELEASE_IDOpen the document in the Presentation Tool
Without a mode parameter, an edit intent link opens the document in the first tool in the workspace that can edit it, usually the Structure Tool. Add mode=presentation to open it in the Presentation Tool instead, with the document's form next to the preview. mode=structure always opens the Structure Tool.
The Presentation Tool needs both id and type. path focuses the field in the form, the same as in the Structure Tool. These parameters control the preview:
preview=/blog/my-postloads that page in the preview. A relative path resolves against the origin of the preview URL. A full URL works when its origin matchesallowOriginsin the Presentation Tool configuration. Otherwise the studio shows a "Blocked preview URL" error and the preview stays on its current page. Withoutpreview, the preview opens at the page the Presentation Tool is already showing, or at/.viewport=mobileopens the preview at mobile width.presentation=TOOL_NAMEselects a Presentation Tool by itsnamewhen the workspace has more than one.
<your-studio-url>/intent/edit/mode=presentation;id=post-123;type=post;path=title;preview=%2Fblog%2Fmy-postConstruct edit URLs programmatically
You can construct edit intent URLs programmatically. The following helper function builds URLs for documents, specific fields, and nested field paths:
// Helper function to create edit intent URLs
function createEditUrl({
studioUrl,
documentId,
documentType,
path = '',
}) {
// Intent parameters go in a single path segment, separated by semicolons
const params = [`id=${documentId}`, `type=${documentType}`]
if (path) {
params.push(`path=${encodeURIComponent(path)}`)
}
return `${studioUrl}/intent/edit/${params.join(';')}`
}
// Create link to edit a document
const editPostUrl = createEditUrl({
studioUrl: '<your-studio-url>',
documentId: 'post-123',
documentType: 'post',
})
// <your-studio-url>/intent/edit/id=post-123;type=post
// Create link to edit a specific field
const editTitleUrl = createEditUrl({
studioUrl: '<your-studio-url>',
documentId: 'post-123',
documentType: 'post',
path: 'title',
})
// <your-studio-url>/intent/edit/id=post-123;type=post;path=title
// Create link to edit nested field
const editAuthorNameUrl = createEditUrl({
studioUrl: '<your-studio-url>',
documentId: 'post-123',
documentType: 'post',
path: 'author.name',
})
// <your-studio-url>/intent/edit/id=post-123;type=post;path=author.nameAdd edit buttons to a preview interface
You can use edit intent URLs to add edit buttons to your preview interface. Here are examples for document-level and field-level edit links:
// React component with edit button
function PostPreview({post}) {
const editUrl = createEditUrl({
studioUrl: process.env.NEXT_PUBLIC_STUDIO_URL,
documentId: post._id,
documentType: post._type,
})
return (
<article>
<header>
<h1>{post.title}</h1>
<a
href={editUrl}
target="_blank"
rel="noopener noreferrer"
className="edit-button"
>
Edit in Studio
</a>
</header>
<div>{post.body}</div>
</article>
)
}
// Field-level edit links
function EditableField({value, documentId, documentType, fieldPath}) {
const editUrl = createEditUrl({
studioUrl: process.env.NEXT_PUBLIC_STUDIO_URL,
documentId,
documentType,
path: fieldPath,
})
return (
<div className="editable-field">
<span>{value}</span>
<a href={editUrl} className="edit-icon" title="Edit this field">
✏️
</a>
</div>
)
}Build edit links inside Sanity Studio
In code that runs inside your studio, such as a custom input or a document action, let the router build the link. IntentLink and resolveIntentLink() from sanity/router encode the parameters and add the workspace base path:
import {IntentLink, useRouter} from 'sanity/router'
interface EditHeadingLinkProps {
documentId: string
sectionKey: string
}
export function EditHeadingLink(props: EditHeadingLinkProps) {
const {documentId, sectionKey} = props
return (
<IntentLink
intent="edit"
params={{
id: documentId,
type: 'page',
path: `sections[_key=="${sectionKey}"].heading`,
}}
>
Edit heading
</IntentLink>
)
}
// Returns a path relative to the studio origin
export function useHistoryUrl(documentId: string): string {
const {resolveIntentLink} = useRouter()
return resolveIntentLink('edit', {
id: documentId,
type: 'page',
inspect: 'sanity/structure/history',
})
}Resolve edit URLs from a Content Source Map
When you render query results, you don't always have the document ID and type at hand. A slug used to build a URL, for example, never appears on the page. resolveEditUrl from @sanity/client/csm takes a path into a query result and resolves the source document, type, and field path from the query's Content Source Map.
Alpha API
resolveEditUrl is marked @alpha in @sanity/client, and the createEditUrl function it calls is marked @internal. Both work today, but the signature and the URL they produce can change in a minor release.
Two settings are required before you can resolve a URL:
- Set
resultSourceMap: 'withKeyArraySelector'in the client config. Plaintruealso returns a source map, but links to array items break when the array is reordered. - Pass
filterResponse: falsetoclient.fetch(). The default response contains the result only, without the source map.
import { createClient } from '@sanity/client'
import { resolveEditUrl } from '@sanity/client/csm'
const client = createClient({
projectId: '<your-project-id>',
dataset: 'production',
apiVersion: '2026-07-01',
useCdn: false,
// 'withKeyArraySelector' keeps links to array items stable when the array is reordered
resultSourceMap: 'withKeyArraySelector',
})
const { result, resultSourceMap } = await client.fetch(
'*[_type == "author" && slug.current == $slug][0]{name, slug, pictures}',
{ slug: 'john-doe' },
// Without this, the response contains the result only
{ filterResponse: false }
)
// resultSourceMap is undefined unless the client asks for it
const editAltTextUrl = resultSourceMap
? resolveEditUrl({
studioUrl: '<your-studio-url>',
resultSourceMap,
// A path into the query result, as a string or an array of segments
resultPath: 'pictures[0].alt',
})
: undefinedThe resolved URL carries the intent parameters as a path segment and repeats them as a query string:
<your-studio-url>/intent/edit/mode=presentation;id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures%5B_key%3D%3D%22cee5fbb69da2%22%5D.alt?baseUrl=YOUR_STUDIO_URL&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=author&path=pictures%5B_key%3D%3D%22cee5fbb69da2%22%5D.alt&perspective=publishedDifferences from a manually built link
Links from resolveEditUrl differ from the ones you build yourself:
- The URL always sets
mode=presentation, so it opens the document in the Presentation Tool rather than the Structure Tool. - A
resultPathis required. The underlyingcreateEditUrlthrowspath is required, so you can't build a document-only link this way. - The field path is percent-encoded, and
perspective=publishedis appended when the source document is published. - Unresolvable paths return
undefined. A value computed in the query maps to no document field, for example. Check the return value before you render a link.
Related resources
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?