variable / @typed/navigation

fromWindow

Provides Navigation by adapting a browser Window’s History API and popstate events.

Package version
1.0.0-beta.7
Category
Browser history provider
Since
1.0.0

Import

import { fromWindow } from "@typed/navigation";

Signatures

export declare const fromWindow: (window?: Window) => Layer.Layer<Navigation, NavigationError, Uuid7State>;

Why

Browser history remains the platform authority while Typed adds reactive entries, stable keys, scoped handlers, and typed failures. Existing or foreign history state is reconciled instead of assuming every entry was created by Typed.

Ownership and lifetime

Layer acquisition reads and normalizes current history, allocates entry identity through Uuid7State, and installs the popstate listener. The Layer Scope owns that listener, pending traversals, reactive state, and handler registrations. Browser calls, malformed URLs, and unknown traversal state fail as NavigationError; interruption runs Effect finalizers but cannot undo a platform history mutation that already completed.

Examples

import { fromWindow } from "@typed/navigation/fromWindow"

const NavigationLive = fromWindow(window)

Browser and server providers expose the same Navigation contract; server code should use @typed/navigation/memory and must not evaluate the default globalThis.window argument.

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source