@wroud/navigation
Version:
A flexible, pattern-matching navigation system for JavaScript applications with built-in routing, browser integration, and navigation state management
55 lines • 1.81 kB
TypeScript
import { type IRoute, type IRouteOptions } from "./IRoute.js";
import type { IRouter } from "./IRouter.js";
import type { IRouteState } from "./IRouteState.js";
import type { IRouteMatcher, RouteParams } from "./IRouteMatcher.js";
export interface RouterOptions<TMatcher extends IRouteMatcher = IRouteMatcher> {
/**
* Matcher implementation to use for routing.
* If not provided, basic routing will be used without pattern matching capabilities.
* If provided, pattern-based routing will be used (route IDs are treated as patterns).
*/
matcher?: TMatcher;
}
export declare class Router<TMatcher extends IRouteMatcher = IRouteMatcher> implements IRouter<TMatcher> {
get routesList(): IRoute[];
private readonly routes;
readonly matcher: TMatcher | null;
constructor(options?: RouterOptions<TMatcher>);
/**
* Add a route to the router
*/
addRoute(route: IRouteOptions): void;
/**
* Get a route's parent
*/
getParentRoute(routeId: string): IRoute | undefined;
/**
* Get the full route hierarchy for a route
*/
getRouteTree(routeId: string): IRoute[];
/**
* Get a route by ID
*/
getRoute(routeId: string): IRoute | undefined;
/**
* Match a URL to a route
*/
matchUrl(url: string): IRouteState | null;
/**
* Build a URL from a route ID and parameters
*/
buildUrl(routeId: string, params: RouteParams): string | null;
/**
* Convert a route state to a URL
*/
stateToUrl(state: IRouteState): string | null;
/**
* Convert a URL to a route state
*/
urlToState(url: string): IRouteState | null;
/**
* Calculates parent route IDs for a given route ID
*/
private getParentsForRoute;
}
//# sourceMappingURL=Router.d.ts.map