UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

31 lines (30 loc) 1.91 kB
import type { ReactElement, ReactNode } from "react"; import { type TreeElement } from "../../util/element.js"; import { type AbsolutePath } from "../../util/path.js"; import type { PossibleMeta } from "../util/index.js"; /** Extras threaded through `TreeRouterMapper` to the page renderer — the site-root-relative path of the page. */ interface TreeRouterExtras { /** Site-root-relative URL path of the page being rendered. Each page forwards it to its child cards. */ readonly path: AbsolutePath; } /** Mapping + Mapper pair for tree routers — wrap children in `<TreeRouterMapping>` to override. */ export declare const TreeRouterMapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps<TreeRouterExtras>>, TreeRouterMapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps<TreeRouterExtras>>; export interface TreeRouterProps extends PossibleMeta { /** The tree of elements to match routes for. */ readonly tree: TreeElement; /** * Optional fallback element. * - Explicit `null` means fallback to nothing (router will not throw `NotFoundError`). */ readonly fallback?: ReactElement | undefined | null; } /** * Resolve a URL path to a tree element and render it as a full page. * - Walks the tree by matching each path segment to a descendant's `key` (via `resolveElementPath()`). * - `/` renders the root itself; deeper paths render the matching descendant. * - `path` is the site-root-relative path (already stripped of any `APP_URL` subfolder by `<Router>`); it is threaded to the page renderer so child cards build correct hrefs. * - Throws `NotFoundError` if no element matches at any level. * - To override the renderer for a specific element type, wrap in `<TreeRouterMapping mapping={…}>`. */ export declare function TreeRouter({ tree, fallback, ...meta }: TreeRouterProps): ReactNode; export {};