variable / @typed/router/Route

Parse

Parses a route-pattern string into a typed Route.

Package version
1.0.0-beta.13
Category
Route construction
Since
1.0.0

Import

import { Parse } from "@typed/router/Route";

Signatures

export declare const Parse: <const P extends string>(path: P) => Route<Path.Join<Path.ParseAsts<P>>>;

Why

It is the primary constructor for literals, named parameters, optional parameters, regular- expression parameters, wildcards, and query declarations. The special ?? boundary separates a terminal optional path parameter from query syntax.

Ownership and lifetime

Parse constructs its Route immediately. The Route retains the supplied AST or route values and lazily memoizes derived paths and Codecs; Codec services are required only when decoding or encoding runs.

Examples

import * as Router from "@typed/router"

const User = Router.Parse("/users/:id?tab=:tab?")
// Router.Type<typeof User> is { readonly id: string; readonly tab?: string }

Other public imports

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

Source