class / @typed/router/CurrentRoute

CurrentRoute

The ambient route context for the current routing boundary.

Package version
1.0.0-beta.13
Category
Structural mounts
Since
1.0.0

Import

import { CurrentRoute } from "@typed/router/CurrentRoute";

Signatures

export declare class CurrentRoute extends CurrentRoute_base {
    static readonly Default: Layer.Layer<CurrentRoute, never, Navigation>;
    static readonly extend: (route: Route.Any) => Layer.Layer<CurrentRoute, never, never>;
}

Why

A stable ambient context prevents same-route parameter updates from replacing structural ownership. Use Navigation for the live URL; use CurrentRoute for the route tree that owns this handler.

Ownership and lifetime

The selected handler or layout Scope owns the provided service. Default creates the root from Navigation.base; extend shadows it for a nested boundary and retains the previous value as parent.

Property: Default

Provides the root mount route parsed from Navigation.base.

Property: Default: Why

Every router needs a structural root even before a matcher selects a child route.

Property: Default: Ownership and lifetime

The Layer borrows Navigation and provides CurrentRoute for its surrounding Layer Scope.

Property: extend

Provides a nested CurrentRoute whose parent is the ambient mount boundary.

Property: extend: Why

An independently owned child Matcher declares paths relative to this mount. The supplied Route is the exact child mount, not an automatically joined relative segment; compose deeper prefixes with Route.Join before extending. Navigation remains shared with the surrounding app.

Property: extend: Ownership and lifetime

Layer acquisition reads the ambient context once. The returned child tree lives until that Layer Scope closes.

Examples

import * as Router from "@typed/router"
import * as Effect from "effect/Effect"

const mountedPath = Effect.map(Router.CurrentRoute, ({ route }) => route.path)

Other public imports

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

Source