import { LimeWebComponent } from '../core'; /** * The {@link RouteRegistry} service lets you register new locations in the * application specified by either a path or a path pattern. Once a location * has been registered, it can be navigated to using the {@link Navigator} * service. * * When registering a route, any parameters in the path will be used as props * on the component when it is being rendered. Parameters will be of type * `string`, when the parameter can be parsed as a number the type will instead * be `number`. Components that are registered in the {@link RouteRegistry} * should implement {@link RouteComponent}. * * @note Since components are assumed to implement {@link RouteComponent} some * parameters can not be used as path parameters and some will have special * meaning. Special handling will be used for parameters named `limetype` and * `id` to create a {@link LimeWebComponentContext} for the component. `id` can * be used on it's own, but will be used to create `context` if `limetype` is * also present. The following should not be used since they are part of * {@link RouteComponent}: * - `platform` * - `context` * - `query` * - `hash` * - `state` * * @example * // Registering a simple route * routeRegistry.registerRoute('/foo', 'foo-component'); * * @example * // Registering a route with parameters * // `name` will be used as a prop on the component when it renders * routeRegistry.registerRoute('/foo/:name', 'foo-component'); * * @example * // Registering a route with a context * // The `context` prop of the component will have the values of the * // `limetype` and `id` parameters * routeRegistry.registerRoute('/foo/:limetype/:id', 'foo-component'); * * @experimental */ export interface RouteRegistry { /** * Register a route for a component. * * @param {string} pathPattern - path pattern used to match a component. * For more information about URL patterns read [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API). * @param {string} component - Name of the component to register for the * specified pattern */ registerRoute(pathPattern: string, component: string): void; /** * Find the component for a given path. * * @param {string} path - The path to match against. * @return {MatchedComponent | undefined} the matched component along with * path parameters, or `undefined` if no component could be found. */ findComponent(path: string): MatchedComponent | undefined; } export declare type MatchedComponent = { /** * The name of the component. */ name: string; /** * Matched path parameters. */ props: Record; }; /** * Interface for components that are routed to and are registered with the * {@link RouteRegistry} service. * * @experimental */ export interface RouteComponent extends LimeWebComponent { /** * Query parameters from the route URL */ query?: Record; /** * The URL fragment identifier */ hash?: string; /** * The history state */ state?: unknown; }