/** * Universal Router (https://www.kriasoft.com/universal-router/) * * Copyright (c) 2015-present Kriasoft. * * This source code is licensed under the MIT license found in the * LICENSE.txt file in the root directory of this source tree. */ import type { EmptyObject } from 'type-fest'; import type { ActionResult, Route, MaybePromise, ResolveContext, RouteContext } from './types.t.js'; export interface ResolutionErrorOptions { code?: number; cause?: unknown; } /** * An error that is thrown when a route resolution fails. */ export declare class ResolutionError extends Error { /** * The resolution error cause, possibly an error thrown from the action callback. */ readonly cause?: unknown; /** * A HTTP status code associated with the error. */ readonly code?: number; /** * The context object associated with the route that was not found. */ readonly context: RouteContext; constructor(context: RouteContext, options?: ResolutionErrorOptions); /** * Logs the error message to the console as a warning. */ warn(): void; } /** * A callback function that handles errors during route resolution. */ export type ErrorHandlerCallback = (error: unknown) => T; /** * A callback function that resolves a route. It is used as a fallback in case * the route is not correctly resolved. */ export type ResolveRouteCallback = (context: RouteContext) => MaybePromise>>; /** * Options for the constructor of the `Resolver` class. * * @interface */ export type ResolverOptions = Readonly<{ baseUrl?: string; context?: RouteContext; errorHandler?: ErrorHandlerCallback; resolveRoute?: ResolveRouteCallback; }>; declare class Resolver { #private; /** * The base URL for all routes in the router instance. By default, * if the base element exists in the ``, vaadin-router * takes the `` attribute value, resolved against the current * `document.URL`. */ readonly baseUrl: string; readonly errorHandler?: ErrorHandlerCallback; readonly resolveRoute: ResolveRouteCallback; constructor(routes: ReadonlyArray> | Route, options?: ResolverOptions); /** * The root route. */ get root(): Route; /** * The current route context. */ get context(): RouteContext; /** * If the baseUrl property is set, transforms the baseUrl and returns the full * actual `base` string for using in the `new URL(path, base);` and for * prepernding the paths with. The returned base ends with a trailing slash. * * Otherwise, returns empty string. */ protected get __effectiveBaseUrl(): string; /** * Returns the current list of routes (as a shallow copy). Adding / removing * routes to / from the returned array does not affect the routing config, * but modifying the route objects does. * * @public */ getRoutes(): ReadonlyArray>; /** * Removes all existing routes from the routing config. * * @public */ removeRoutes(): void; /** * Asynchronously resolves the given pathname, i.e. finds all routes matching * the pathname and tries resolving them one after another in the order they * are listed in the routes config until the first non-null result. * * Returns a promise that is fulfilled with the return value of an object that consists of the first * route handler result that returns something other than `null` or `undefined` and context used to get this result. * * If no route handlers return a non-null result, or if no route matches the * given pathname the returned promise is rejected with a 'page not found' * `Error`. * * @param pathnameOrContext - the pathname to * resolve or a context object with a `pathname` property and other * properties to pass to the route resolver functions. */ resolve(pathnameOrContext: ResolveContext | string): Promise>>; /** * Sets the routing config (replacing the existing one). * * @param routes - a single route or an array of those * (the array is shallow copied) */ setRoutes(routes: ReadonlyArray> | Route): object; /** * If the baseUrl is set, matches the pathname with the router’s baseUrl, * and returns the local pathname with the baseUrl stripped out. * * If the pathname does not match the baseUrl, returns undefined. * * If the `baseUrl` is not set, returns the unmodified pathname argument. */ protected __normalizePathname(pathname: string): string | undefined; /** * Appends one or several routes to the routing config and returns the * effective routing config after the operation. * * @param routes - a single route or an array of those * (the array is shallow copied) */ protected addRoutes(routes: ReadonlyArray> | Route): ReadonlyArray>; } export default Resolver; //# sourceMappingURL=resolver.d.ts.map