Sanity Library Reference Docs
    Preparing search index...

    Base class for immutable URL grammars.

    Implements

    Index

    Constructors

    Methods

    Constructors

    • Creates an immutable URL builder at the supplied URL.

      Parameters

      • url: URL

      Returns UrlBuilder

      const builder = new UrlBuilder(
      new URL('/applications/my-app', 'https://dashboard.sanity.io'),
      )

      builder.url() // '/applications/my-app'

    Methods

    • Returns the URL as a platform URL object using the supplied origin.

      Parameters

      • __namedParameters: { origin: string }

      Returns URL

      const builder = new UrlBuilder(
      new URL('/applications/my-app', 'https://dashboard.sanity.io'),
      )

      builder.toURL({origin: 'https://dashboard.sanity.io'}).pathname
      // '/applications/my-app'
    • Returns the URL as a relative string by default.

      Supplying an origin returns an absolute URL string for the same dashboard route.

      Parameters

      • Optionaloptions: { origin?: string }

      Returns string

      const builder = new UrlBuilder(
      new URL('/applications/my-app', 'https://dashboard.sanity.io'),
      )

      builder.url() // '/applications/my-app'
      builder.url({origin: 'https://dashboard.sanity.io'})
      // 'https://dashboard.sanity.io/applications/my-app'