/** @typedef {{ path: string, pattern: string, params: object }} RouteObject */ export class Router { /** * @param {{ routes?: Array, scrollRestoration?: ScrollRestoration }} [options] */ constructor({ routes, scrollRestoration }?: { routes?: any[]; scrollRestoration?: ScrollRestoration; }); /** @type {Array} */ routes: Array; /** @type {RouteObject} */ currentRoute: RouteObject; _handleBeforeEach: (route: RouteObject) => any | null; _handleAfterEach: (route: RouteObject) => any | null; /** * Add a new route. * @param {string} path - A path or a pattern (e.g.: `/user/:id`). * @param {import("./Route").RouteAction} action A function that is called * when the route is entered. The route parameters are passed as object. */ route(path: string, action: import("./Route").RouteAction): void; /** * Push a new route. * @param {string} path */ push(path: string): void; /** * Replace current route with a new route. * @param {string} path */ replace(path: string): void; init(): void; /** * @param {(route: RouteObject) => any?} callback */ beforeEach(callback: (route: RouteObject) => any | null): void; /** * @param {(route: RouteObject) => any?} callback */ afterEach(callback: (route: RouteObject) => any | null): void; /** * Search for the first route that matches the path and call the routes * callback. * @private * @param {string} path * @param {boolean} initial */ private _handleChange; } export type RouteObject = { path: string; pattern: string; params: object; }; import { Route } from "./Route.js";