[]previous and next page

RouterWindow

The window a router uses for popstate, scroll events and storage.

The window a router uses for popstate, scroll events and storage. It is a browser window or a test double with the same members. Without one, the router is a memory router: no scroll restoration and no listeners.

Import#

ts
import type { RouterWindow } from "@shadow-js/router";

Signature#

ts
interface RouterWindow extends WindowLike {
  readonly scrollX?: number;
  readonly scrollY?: number;
  readonly scrollTo?: ((x: number, y: number) => void) | undefined;
  readonly requestAnimationFrame?: ((callback: () => void) => unknown) | undefined;
  readonly history: WindowLike["history"] & { scrollRestoration?: "auto" | "manual" | undefined };
  addEventListener(type: string, listener: (event: never) => void): void;
  removeEventListener(type: string, listener: (event: never) => void): void;
  readonly sessionStorage?: {
    getItem(key: string): string | null;
    setItem(key: string, value: string): void;
  };
  readonly document?: {
    readonly getElementById?: ((id: string) => FragmentTarget | null) | undefined;
    readonly startViewTransition?:
      | ((
          update: (() => void) | { readonly update: () => void; readonly types?: string[] },
        ) => unknown)
      | undefined;
  };
  /** The `ViewTransition` class, present where transition types are supported. */
  readonly ViewTransition?: { readonly prototype: object } | undefined;
  readonly matchMedia?: ((query: string) => { readonly matches: boolean }) | undefined;
}

Members#

Name Type Description
scrollX? readonly scrollX?: number
scrollY? readonly scrollY?: number
scrollTo? readonly scrollTo?: ((x: number, y: number) => void) | undefined
requestAnimationFrame? readonly requestAnimationFrame?: ((callback: () => void) => unknown) | undefined
history readonly history: WindowLike["history"] & { scrollRestoration?: "auto" | "manual" | undefined }
addEventListener addEventListener(type: string, listener: (event: never) => void): void
removeEventListener removeEventListener(type: string, listener: (event: never) => void): void
sessionStorage? readonly sessionStorage?: { getItem(key: string): string | null; setItem(key: string, value: string): void; }
document? readonly document?: { readonly getElementById?: ((id: string) => FragmentTarget | null) | undefined; readonly startViewTransition?: | (( update: (() => void) | { readonly update: () => void; readonly types?: string[] }, ) => unknown) | undefined; }
ViewTransition? readonly ViewTransition?: { readonly prototype: object } | undefined The ViewTransition class, present where transition types are supported.
matchMedia? readonly matchMedia?: ((query: string) => { readonly matches: boolean }) | undefined