| 1 |
|
| 2 | import { Equal } from "./types/utils.js";
|
| 3 | import { Pages } from "./types/register.js";
|
| 4 |
|
| 5 | //#region lib/href.d.ts
|
| 6 | type Args = { [K in keyof Pages]: ToArgs<Pages[K]["params"]> };
|
| 7 | type ToArgs<Params extends Record<string, string | undefined>> = Equal<Params, {}> extends true ? [] : Partial<Params> extends Params ? [Params] | [] : [Params];
|
| 8 | /**
|
| 9 | * Returns a resolved URL path for the specified route.
|
| 10 | *
|
| 11 | * Param values are percent-encoded for use in a path segment: characters that
|
| 12 | * would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
| 13 | * are escaped, while characters that RFC 3986 allows literally in a path
|
| 14 | * segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
| 15 | * encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
| 16 | * delimiters and must be escaped. Splat (`*`) values are encoded per segment,
|
| 17 | * preserving `/` separators.
|
| 18 | *
|
| 19 | * See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
| 20 | *
|
| 21 | * @example
|
| 22 | * const h = href("/:lang?/about", { lang: "en" })
|
| 23 | * // -> `/en/about`
|
| 24 | *
|
| 25 | * <Link to={href("/products/:id", { id: "abc123" })} />
|
| 26 | *
|
| 27 | * @public
|
| 28 | * @category Utils
|
| 29 | * @mode framework
|
| 30 | * @param path The route path to resolve
|
| 31 | * @param args The route params to use when resolving the path
|
| 32 | * @returns The resolved URL path
|
| 33 | */
|
| 34 | declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
|
| 35 | //#endregion
|
| 36 | export { href }; |
| \ | No newline at end of file |