UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

24 lines (23 loc) 1.35 kB
import type { ReactElement } from "react"; import type { PossibleMeta } from "../util/meta.js"; import type { Routes } from "./Routes.js"; export interface RouterProps extends PossibleMeta { /** List of routes for the router to match against. */ readonly routes: Routes; /** * Optional fallback element. * - Explicit `null` means fallback to nothing (router will not throw `NotFoundError`). */ readonly fallback?: ReactElement | undefined | null; } /** * Match the current URL against `routes` and render the matched element. * - Reads `url` and `base` from the surrounding `<Meta>` context (override via props). * - When `base` is set, the effective path is the URL after stripping the base prefix. * - Nest by putting another `<Router>` inside a route's value; pass `base="/section"` (or wrap in `<Meta>`) to scope. * - Route `{placeholders}` are passed as props to function/component route values along with merged URL `?query` params. They are not published into context — descendants of a `ReactElement`-valued route can't see them automatically. * - Returns `null` when there's no URL in context or the URL is outside the base. * * @throws {NotFoundError} if no route matches and `fallback` is `undefined` */ export declare function Router({ routes, fallback, ...meta }: RouterProps): ReactElement | null;