ExperimentalDiagnose why a document ID fails (or succeeds) to resolve to a URL.
Uses realtime GROQ evaluation to check each step of the resolution pipeline.
Returns a detailed result with a status code and human-readable message.
Use this for debugging when resolveUrlById returns null.
Published document ID to diagnose
Optionaloptions: LocaleOptionsLocale options for i18n routes
Diagnosis result with status, message, and contextual data
const result = await resolver.diagnose('my-doc')
if (result.status === 'no_route_entry') {
console.log(result.availableRoutes) // ['blogPost', 'page']
}
The 6-status contract may evolve.
DiagnosisResult for the full result shape
List all document types that have route entries in the config.
Array of document type names (e.g., ['blogPost', 'article', 'product'])
ExperimentalGenerate GROQ custom function declarations for all routable types.
Each declaration creates a routes::{type}Path($id) function that looks up
the path from the route map shard. Useful for embedding route resolution
in GROQ queries without client-side processing.
Newline-separated function declarations
Subscribe to route config changes and invalidate the internal cache.
Call this in long-running processes (e.g., dev servers) to keep the resolver's cached config fresh when route configuration changes in Studio.
Unsubscribe function. Call it to stop listening.
Returns a GROQ projection expression for the path portion of a route.
The returned expression resolves to the relative path only — it does NOT include baseUrl or basePath. Use this to embed URL resolution directly in GROQ queries.
Document type name (e.g., 'blogPost')
A GROQ projection string like "path": slug.current
Load all route map shards into a Map for synchronous URL lookups.
Requires route map shards built by buildRouteMap() or the sync Function.
Returns a Record of document ID → full URL for every document in the route map.
Ideal for Portable Text rendering where you need synchronous access to URLs
for internal link marks.
Optionaloptions: LocaleOptionsLocale options. When set, loads locale-specific shards.
Record of document ID → full URL. Empty record if no shards exist.
// Preload in parallel with content fetch
const [post, urlMap] = await Promise.all([
client.fetch(`*[_type == "blogPost" && slug.current == $slug][0]`, { slug }),
resolver.preload(),
])
// Synchronous lookup in Portable Text renderer — no async, no waterfall
const components = {
marks: {
internalLink: ({ value, children }) => (
<a href={urlMap[value.reference._ref] ?? '#'}>{children}</a>
),
},
}
Rebuild the route map shard for a specific document type.
Requires route map shards infrastructure (the sync Function or buildRouteMap()).
Fetches all documents of the given type, evaluates their pathExpression,
and writes the shard to Content Lake via createOrReplace. When the route
has locales configured and no specific locale is passed, rebuilds all
locale-specific shards.
Document type name to rebuild (e.g., 'blogPost')
Optionaloptions: LocaleOptionsLocale options. Pass a specific locale to rebuild only that shard.
Reverse-resolve a URL to the document that produces it.
Requires route map shards built by buildRouteMap() or the sync Function.
Scans all shards to find the document whose assembled URL matches the input.
Accepts full URLs or path-only input. Normalizes trailing slashes,
query parameters, and fragments before comparison.
Full URL or path to resolve (e.g., 'https://example.com/blog/hello' or '/blog/hello')
The document ID and type, or null if no match is found
Resolve a document ID to just the URL pathname (no origin).
Uses realtime GROQ evaluation. Convenience wrapper around
resolveUrlById that extracts the pathname.
Use this for Next.js <Link href>, internal routing, and redirect().
Published document ID
Optionaloptions: LocaleOptionsLocale options for i18n routes
The pathname (e.g., /docs/ai/agent-context), or null if unresolvable.
Resolve multiple document IDs to their pathnames in a single batch.
Uses realtime GROQ evaluation.
Array of published document IDs
Optionaloptions: LocaleOptionsLocale options for i18n routes
Record of document ID → pathname. Unresolvable IDs are omitted.
Resolve a single document ID to its full URL.
Uses realtime GROQ evaluation — always returns the freshest result.
Published document ID to resolve. Use @sanity/id-utils to normalize draft/version IDs.
Optionaloptions: LocaleOptionsLocale options for i18n routes
The full URL including base URL and basePath, or null if the document
can't be resolved (missing document, no route entry, or empty path).
Use diagnose to determine the specific failure reason.
const url = await resolver.resolveUrlById('article-123')
// → 'https://example.com/docs/getting-started'
Resolve multiple document IDs to their full URLs in a single batch.
Uses realtime GROQ evaluation. More efficient than calling resolveUrlById in a loop — groups documents by route entry for batch GROQ evaluation.
Array of published document IDs to resolve
Optionaloptions: LocaleOptionsLocale options for i18n routes
Record of document ID → full URL. IDs that can't be resolved are omitted (not null).
Unified route resolver with all URL resolution methods.
Created via createRouteResolver. Combines realtime GROQ evaluation (for
resolveUrlById,pathProjection,listen, etc.) with static shard lookups (forpreload,resolveDocumentByUrl,rebuildType).Example
See
createRouteResolver to create a resolver instance