HrefOf
Targets accepted by typed navigation: a registered pattern (/posts/:id, used with params), an href that matches one (/posts/${string}), or a RuntimeHref made by unsafeHref for a path that was validated at run time.
Targets accepted by typed navigation: a registered pattern (/posts/:id, used with params),
an href that matches one (/posts/${string}), or a RuntimeHref made by unsafeHref for a
path that was validated at run time. Plain string when no paths are registered.
Limits: a :param or splat matches any text, including /, because TypeScript cannot exclude a
character from a template literal. A static pattern accepts ? and # tails too, so /about also
takes /about?tab=2 and /about#team.
Import#
ts
import type { HrefOf } from "@shadow-js/router";
Signature#
ts
type HrefOf<P extends string = RegisteredPath> = string extends P
? string
: P | PatternHref<P> | RuntimeHref
Examples#
ts
```ts
type Edit = HrefOf<"/posts/:id/edit">;
const ok: Edit = "/posts/7/edit?tab=2";
// @ts-expect-error the tail is /edit, not /delete
const bad: Edit = "/posts/7/delete";