Visual Editing

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:

/intent/edit/id=DOCUMENT_ID;type=DOCUMENT_TYPE;path=FIELD_PATH

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:

  • id is the published document ID, without a drafts. or versions. prefix. To open a version in a release, add ?perspective=RELEASE_ID to the URL.
  • type is 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.
  • path is the field to focus. Encode it with encodeURIComponent: the studio splits each parameter on =, so an unencoded body[_key=="a1b2c3"] is cut short at body[_key and the link doesn't focus the field you asked for. Leave path out 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.metaTitle focuses a field inside an object.
  • sections[_key=="a1b2c3"].heading focuses 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/history opens the document's history.
  • inspect=sanity/structure/validation opens the validation panel.
  • inspect=sanity/structure/incoming-references opens the documents that reference this one.
  • inspect=sanity/comments opens comments. Add comment=COMMENT_ID to select a comment thread.
  • view=VIEW_ID opens a document view defined with S.document().views().

To open a version in a release, add ?perspective=RELEASE_ID after the path segment. ?perspective=published opens the published version.

/intent/edit/id=page-home;type=page;path=sections%5B_key%3D%3D%22a1b2c3%22%5D.heading;inspect=sanity%2Fstructure%2Fhistory?perspective=RELEASE_ID

Open 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-post loads that page in the preview. A relative path resolves against the origin of the preview URL. A full URL works when its origin matches allowOrigins in the Presentation Tool configuration. Otherwise the studio shows a "Blocked preview URL" error and the preview stays on its current page. Without preview, the preview opens at the page the Presentation Tool is already showing, or at /.
  • viewport=mobile opens the preview at mobile width.
  • presentation=TOOL_NAME selects a Presentation Tool by its name when the workspace has more than one.
/intent/edit/mode=presentation;id=post-123;type=post;path=title;preview=%2Fblog%2Fmy-post

Construct 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: '',
  documentId: 'post-123',
  documentType: 'post',
})
// /intent/edit/id=post-123;type=post

// Create link to edit a specific field
const editTitleUrl = createEditUrl({
  studioUrl: '',
  documentId: 'post-123',
  documentType: 'post',
  path: 'title',
})
// /intent/edit/id=post-123;type=post;path=title

// Create link to edit nested field
const editAuthorNameUrl = createEditUrl({
  studioUrl: '',
  documentId: 'post-123',
  documentType: 'post',
  path: 'author.name',
})
// /intent/edit/id=post-123;type=post;path=author.name

Add 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

Two settings are required before you can resolve a URL:

  • Set resultSourceMap: 'withKeyArraySelector' in the client config. Plain true also returns a source map, but links to array items break when the array is reordered.
  • Pass filterResponse: false to client.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: '',
  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: '',
      resultSourceMap,
      // A path into the query result, as a string or an array of segments
      resultPath: 'pictures[0].alt',
    })
  : undefined

The resolved URL carries the intent parameters as a path segment and repeats them as a query string:

/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=published

Differences 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 resultPath is required. The underlying createEditUrl throws path is required, so you can't build a document-only link this way.
  • The field path is percent-encoded, and perspective=published is 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?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme