import { URLPattern } from 'urlpattern-polyfill/urlpattern'; import type { AdapterElement } from '../adapter/adapter-element.ts'; import type { ReactiveController, ReactiveControllerHost } from '../shared/reactive-controller.ts'; export interface BaseRouteConfig { name?: string | undefined; render?: (params: Record, result?: any) => unknown; enter?: (params: Record) => any | Promise; } /** * A RouteConfig that matches against a `path` string. `path` must be a * [`URLPattern` compatible pathname pattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern/pathname). */ export interface PathRouteConfig extends BaseRouteConfig { path: string; } /** * A RouteConfig that matches against a given [`URLPattern`](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) * * While `URLPattern` can match against protocols, hostnames, and ports, * routes will only be checked for matches if they're part of the current * origin. This means that the pattern is limited to checking `pathname` and * `search`. */ export interface URLPatternRouteConfig extends BaseRouteConfig { pattern: URLPattern; } /** * A description of a route, which path or pattern to match against, and a * render() callback used to render a match to the outlet. */ export type RouteConfig = PathRouteConfig | URLPatternRouteConfig; /** * A reactive controller that performs location-based routing using a * configuration of URL patterns and associated render callbacks. */ export declare class Routes implements ReactiveController { protected readonly host: ReactiveControllerHost & (HTMLElement | AdapterElement); static baseUrl: string; static readonly base: string; static waitForRouting(): Promise; protected static readonly routing: Set>; protected static readonly routeMeta: WeakMap; constructor(host: ReactiveControllerHost & (HTMLElement | AdapterElement), routes?: RouteConfig[], options?: { fallback?: BaseRouteConfig; }); routes: RouteConfig[]; /** * A default fallback route which will always be matched if none of the * {@link routes} match. Implicitly matches to the path "/*". */ fallback?: BaseRouteConfig; protected readonly childRoutes: Routes[]; protected parentRoutes: Routes | undefined; protected currentPathname: string | undefined; protected currentRoute: RouteConfig | undefined; protected currentParams: Record; protected previousPathname: string; /** * Callback to call when this controller is disconnected. * * It's critical to call this immediately in hostDisconnected so that this * controller instance doesn't receive a tail match meant for another route. */ protected onDisconnect: (() => void) | undefined; /** * Returns a URL string of the current route, including parent routes, * optionally replacing the local path with `pathname`. */ link(pathname?: string): string; /** * Navigates this routes controller to `pathname`. * * This does not navigate parent routes, so it isn't (yet) a general page * navigation API. It does navigate child routes if pathname matches a * pattern with a tail wildcard pattern (`/*`). */ goto(pathname: string): Promise; /** * The result of calling the current route's render() callback. */ outlet(): ReturnType> | undefined; /** * The current parsed route parameters. */ get params(): Record; /** * Matches `url` against the installed routes and returns the first match. */ protected getRoute(pathname: string): RouteConfig | undefined; hostConnected(): void; hostDisconnected(): void; protected onRoutesConnected: (e: RoutesConnectedEvent) => void; } /** * This event is fired from Routes controllers when their host is connected to * announce the child route and potentially connect to a parent routes controller. */ export declare class RoutesConnectedEvent extends Event { static readonly eventName = "routes-connected"; readonly routes: Routes; onDisconnect?: () => void; constructor(routes: Routes); } //# sourceMappingURL=routes.d.ts.map