import type { Component } from 'svelte'; import type { Location } from './types.js'; import type { RouteDetail, RouteDetailLoaded, RouteDefinition } from './types.js'; export type { ActiveOptions, AsyncSvelteComponent, LinkActionOpts, LinkActionUpateFunc, LinkActionUpdateFunc, Location, RouteDefinition, RouteDetail, RouteDetailLoaded, RoutePrecondition, RouterState, WrappedComponent } from './types.js'; /** Props for the Router component */ export interface RouterProps { /** * Dictionary of all routes, in the format `'/path': component`. * * For example: * ```js * import HomeRoute from './routes/HomeRoute.svelte' * import BooksRoute from './routes/BooksRoute.svelte' * import NotFoundRoute from './routes/NotFoundRoute.svelte' * routes = { * '/': HomeRoute, * '/books': BooksRoute, * '*': NotFoundRoute * } * ``` */ routes: RouteDefinition; /** Optional prefix for the routes in this router. Useful for nested routers. */ prefix?: string | RegExp; /** If true, the router restores scroll positions on back navigation and scrolls to the top on forward navigation. */ restoreScrollState?: boolean; /** Callback fired when route pre-conditions fail. */ onConditionsFailed?: (detail: RouteDetail) => void; /** Callback fired when a route starts loading. */ onRouteLoading?: (detail: RouteDetail) => void; /** Callback fired when a route has loaded. */ onRouteLoaded?: (detail: RouteDetailLoaded) => void; /** Callback for events bubbled up from child components. */ onRouteEvent?: (detail: unknown) => void; } declare class RouterStateImpl { /** The current full location (incl. querystring) */ _loc: Location; /** The current location (excluding querystring) */ _location: string; /** The current querystring */ _querystring: string | undefined; _params: Record | RegExpExecArray | null | undefined; /** The current full location (incl. querystring) */ get loc(): Location; /** The current location (excluding querystring) */ get location(): string; /** The current querystring */ get querystring(): string | undefined; get params(): Record | RegExpExecArray | null | undefined; constructor(); } /** Router state object, containing the current location, querystring and params. */ export declare const router: RouterStateImpl; /** * Navigates to a new page programmatically. * * @param location - Path to navigate to (must start with `/` or `#/`) * @returns Promise that resolves after the page navigation has completed */ export declare function push(location: string): Promise; /** * Navigates back in history (equivalent to pressing the browser's back button). * * @returns Promise that resolves after the page navigation has completed */ export declare function pop(): Promise; /** * Replaces the current page but without modifying the history stack. * * @param location - Path to navigate to (must start with `/` or `#/`) * @returns Promise that resolves after the page navigation has completed */ export declare function replace(location: string): Promise; interface LinkActionInternalOpts { href?: string; disabled?: boolean; } /** * Svelte Action that enables a link element (``) to use our history management. * * For example: * * ```html * View books * ``` */ export declare function link(node: HTMLElement, opts?: LinkActionInternalOpts | string): { update(updated?: LinkActionInternalOpts | string): void; destroy(): void; }; interface ScrollHistoryState { __svelte_spa_router_scrollX?: number; __svelte_spa_router_scrollY?: number; } /** Tries to restore the scroll state from the given history state. */ export declare function restoreScroll(state: ScrollHistoryState | null): void; declare const Router: Component; type Router = ReturnType; export default Router;