3D-City Model
    Preparing search index...

    URLManager – Utility for managing and mutating browser URL query parameters in a type-safe, structured way.

    Encapsulates URL query string parsing, updating, and browser history URL manipulation, providing an easy-to-use API for reading, updating, deleting, and previewing query parameters.

    The browser window object. Required for location/history access.

    get(key, parser?, defaultValue?) - Fetches a parameter, with optional type/array parsing and a default fallback.

    set(key, value) - Sets a query parameter key to value and updates the URL.

    delete(key) - Removes a parameter by key and updates the URL.

    update(updates) - Performs a bulk set/delete on multiple parameters, then updates the URL.

    getUpdatedURLString(updates) - Returns a new URL instance with updates applied, but does not modify the real URL.

    const url = new URLManager(window);
    url.set("mode", "dark");
    url.get("mode") // => "dark"
    url.get("debug", "boolean") // => false
    url.get("id", "number") // => 0 if unset
    url.update({foo: "bar", xyz: undefined});
    url.delete("foo");

    // Preview a URL state:
    const previewUrl = url.getUpdatedURLString({hello: "world"});
    Index

    Constructors

    Properties

    params: URLSearchParams

    Current parsed query parameters (syncs with location.search).

    window: Window

    The window object supplied to the manager.

    Methods

    • Deletes a parameter by key, immediately updating the browser URL.

      Parameters

      • key: string

      Returns void

    • Gets a query parameter's value by key, parsing it optionally as a number, boolean, or array. If the parameter does not exist, returns defaultValue (default: 0).

      Parameters

      • key: string

        Parameter name.

      • Optionalparser: "number" | "boolean" | "array"

        If given, parse the value accordingly.

      • OptionaldefaultValue: any = 0

        Default fallback if not found in query.

      Returns any

      • Parsed value, or the default.
      url.get("id", "number");     // returns a number
      url.get("mode", "boolean"); // returns true/false
      url.get("tags", "array"); // returns ["foo","bar"]
    • Creates and returns a URL instance representing the current page, but with the given updates applied. Does not mutate the real browser URL.

      Parameters

      • updates: Object

        Key/values to set/delete (undefined = delete).

      Returns URL

      const url = urlManager.getUpdatedURLString({foo: "bar"});
      // can use url.href to preview
    • Sets a parameter and updates the URL in the browser.

      Parameters

      • key: string
      • value: any

      Returns void

    • Bulk set/delete for multiple keys. For every property on updates, if value is undefined, deletes it; else sets it.

      Parameters

      • updates: Object

        Key/value pairs (undefined values will trigger deletion).

      Returns void