@sanity/routes
    Preparing search index...

    Function createRouteResolver

    • 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).

      Parameters

      • client: SanityClient

        A configured SanityClient. For shard-based methods (preload, resolveDocumentByUrl) with private shard IDs, the client must have a read token.

      • OptionalchannelOrOptions: string | ResolverOptions

        Route 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: ResolverOptions

        Resolver options including environment and error handling.

      Returns RouteResolver

      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