Sanity Library Reference Docs
    Preparing search index...

    Type Alias DocumentResolver

    DocumentResolver:
        | {
            filter?: never;
            params?: never;
            resolve?: never;
            route: string
            | string[];
            type: string;
        }
        | {
            filter: ContextFn<string>
            | string;
            params?: ContextFn<Record<string, string>> | Record<string, string>;
            resolve?: never;
            route: string | string[];
            type?: never;
        }
        | {
            filter?: never;
            params?: never;
            resolve: ContextFn<
                { filter: string; params?: Record<string, string> }
                | undefined,
            >;
            route: string | string[];
            type?: never;
        }

    Configuration object for resolving documents based on URL route patterns. Used to define the main document when navigating to specific URLs in Presentation tool's preview iframe.

    Supports three different resolution strategies:

    Simple type-based resolution:

    {
    route: '/blog',
    type: 'blog' // Useful for singleton documents
    }

    GROQ filter-based resolution:

    {
    route: '/blog/:category/:slug',
    filter: ({ params }) => `_type == "post" && slug.current == "${params.slug}"`,
    params: ({ params }) => ({ category: params.category })
    }

    Advanced resolution with custom logic:

    {
    route: '/products/:id',
    resolve: ({ params }) => ({
    filter: `_type == "product" && _id == $id`,
    params: { id: params.id }
    })
    }