/** * Single Page Application routing system with multiple target support. * Designed for scenarios where you need: * - Multiple navigation targets (main content, modals, sidebars) * - Strongly typed route parameters * - History management with back/forward support * * @example * // Configure routes * const routes = [ * { name: 'user', path: '/users/:id' }, // String parameter * { name: 'order', path: '/orders/;orderId' }, // Number parameter * { name: 'modal', path: '/detail/:id', target: 'modal' } // Custom target * ]; */ type WebComponentConstructor = new (...args: any[]) => HTMLElement; export declare enum GuardResult { /** * Handle route without checking more guards. */ Allow = 0, /** * Throw a RouteGuardError. */ Deny = 1, /** * Resume and check other guards. */ Continue = 2, /** * Do not invoke the rooute nor other guards. */ Stop = 3 } export interface RouteGuard { check(route: RouteMatchResult): GuardResult; } export interface Route { name?: string; target?: string; path: string; /** * HTML file name (without extension). * * Define for instance if you have a route that requires a more limited layout. The library * will automatically load that HTML file and rewrite URL history so that the correct url is displayed. */ layout?: string; /** * Name of the tag for your web component. */ componentTagName?: string; /** * Guards used to check if this route can be visited. */ guards?: RouteGuard[]; component?: WebComponentConstructor; } export declare const internalRoutes: Route[]; export declare const MyData: { routes: any[]; }; /** * Debug helper to print all registered routes to console. */ export declare function printRoutes(): void; /** * Registers application routes with the router. * Call this at application startup before routing begins. * * @param appRoutes - Array of route configurations * @throws Error if referenced components are not registered * * @example * const routes: Route[] = [ * { name: 'home', path: '/', componentTagName: 'app-home' }, * { name: 'user', path: '/users/:id', componentTagName: 'user-profile' }, * { name: 'login', path: '/auth/', componentTagName: 'login-form', layout: 'noauth' } * ]; * defineRoutes(routes); */ export declare function defineRoutes(appRoutes: Route[]): void; export type RouteParamType = string | number; export type RouteData = Record; /** * Implement to receive typed route parameters via a `routeData` property. * RouteTarget assigns `routeData` after element creation but before DOM insertion. * Optional since it's not available at construction time. * * For convention-based usage without undefined checks, skip the interface * and declare `routeData` directly on your component. * * @example * class UserProfile extends HTMLElement implements Routable<{ userName: string }> { * routeData?: { userName: string }; * } */ export interface Routable { routeData?: T; } /** * Implement to run async initialization before the component is added to the DOM. * RouteTarget calls `loadRoute()` and awaits it before inserting the element. * * @example * class OrderDetail extends HTMLElement implements LoadRoute<{ orderId: number }> { * async loadRoute(data: { orderId: number }) { * this.order = await fetchOrder(data.orderId); * } * } */ export interface LoadRoute { loadRoute(data: T): void | Promise; } /** * Event sent to routing targets when a new route should be displayed. */ export declare class NavigateRouteEvent extends Event { /** * Matched route. */ route: Route; /** * The generated url sements which can be used to push the url into the browser history. */ urlSegments: string[]; /** * Data supplied to the route. */ routeData?: RouteData; /** * The target can differ from the default target that is defined in the route. * * undefined means that the default (unnamed) target should be used. */ routeTarget?: string; static NAME: string; constructor( /** * Matched route. */ route: Route, /** * The generated url sements which can be used to push the url into the browser history. */ urlSegments: string[], /** * Data supplied to the route. */ routeData?: RouteData, /** * The target can differ from the default target that is defined in the route. * * undefined means that the default (unnamed) target should be used. */ routeTarget?: string, eventInit?: EventInit); } declare global { interface HTMLElementEventMap { 'rlx.navigateRoute': NavigateRouteEvent; } interface DocumentEventMap { 'rlx.navigateRoute': NavigateRouteEvent; } } /** * Result from route matching operations. * Contains all information needed for navigation and rendering. */ export type RouteMatchResult = { /** * Matched route configuration */ route: Route; /** * URL segments used for history state */ urlSegments: string[]; /** * Extracted and type-converted parameters */ params: RouteData; }; /** * Supported types of route segments */ export type RouteSegmentType = 'string' | 'number' | 'path' | 'regex'; /** * Strongly typed route segment value */ export interface RouteValue { /** * Type of parameter for validation */ type: RouteSegmentType; /** * Actual parameter value */ value: any; } export declare class RouteError extends Error { } export declare class RouteGuardError extends RouteError { isGuard: any; } export interface NavigateOptions { /** * Optional parameters when using route name */ params?: Record; /** * override for route's default target */ target?: string; /** * When you want to override routes from the globally registered ones. */ routes?: Route[]; } /** * Initializes routing and navigates to the current URL. * Call this after DOM is ready and routes are defined. * * @example * // In your main application component * connectedCallback() { * defineRoutes(routes); * startRouting(); * } */ export declare function startRouting(): void; /** * Navigates to a route by name or URL. * Updates browser history and dispatches navigation events. * * @param routeNameOrUrl - Route name or URL path to navigate to * @param options - Navigation options including params and target * * @example * // Navigate by route name * navigate('user', { params: { id: '123' } }); * * // Navigate by URL * navigate('/users/123'); * * // Navigate to specific target * navigate('detail', { params: { id: '42' }, target: 'modal' }); */ export declare function navigate(routeNameOrUrl: string, options?: NavigateOptions): void; /** * Match route by either name or URL pattern * @param routes Available routes * @param routeNameOrUrl Route name or URL to match * @param routeData Optional parameters for named routes */ export declare function matchRoute(routes: Route[], routeNameOrUrl: string, routeData?: Record): RouteMatchResult | null; /** * Find route by name and apply parameters * @param routes Available routes * @param name Route name to find * @param routeData Parameters to apply */ export declare function findRouteByName(routes: Route[], name: string, routeData?: Record): RouteMatchResult | null; /** * Find route matching URL pattern * @param routes Available routes * @param path URL to match */ export declare function findRouteByUrl(routes: Route[], path: string): RouteMatchResult | null; export {};