A configured SanityClient. For shard-based methods (preload,
resolveDocumentByUrl) with private shard IDs, the client must have a read token.
OptionalchannelOrOptions: string | ResolverOptionsRoute config channel name (e.g., 'web'), or options object.
Optional — when omitted, uses the config marked isDefault: true, or the only
config if exactly one exists.
Optionaloptions: ResolverOptionsResolver options including environment and error handling.
A RouteResolver with all methods.
import { createRouteResolver } from '@sanity/routes'
import { client } from './sanity'
const resolver = createRouteResolver(client, 'web')
// Realtime — evaluates GROQ live, always fresh
const url = await resolver.resolveUrlById('article-123')
// Static — reads from pre-computed shards (requires buildRouteMap or sync Function)
const urlMap = await resolver.preload()
// With environment matching and dev warnings
const resolver = createRouteResolver(client, 'web', {
environment: process.env.SANITY_ROUTES_ENV,
warn: process.env.NODE_ENV !== 'production',
})
RouteResolver for the full method list
Create a unified route resolver for URL resolution from Sanity documents.
Returns a RouteResolver with all methods — both realtime GROQ evaluation (
resolveUrlById,pathProjection,listen, etc.) and static shard lookups (preload,resolveDocumentByUrl,rebuildType).