knave
Version:
Framework-agnostic client-side navigation library
41 lines (39 loc) • 1.79 kB
TypeScript
/**
* Initialize client-side navigation. This function must be called (only once) before any
* navigation occurs.
*/
declare function initialize(
/** Function to be called when a new page should render */
renderFunction: RenderFunction,
/** Whether to install a global click handler for a and area elements */
installGlobalHandler?: boolean): void;
/** Finalize client-side navigation. You can call this function when you don't need client-side navigation anymore. */
declare function finalize(): void;
interface MouseEventLike {
target: EventTarget | null;
defaultPrevented: boolean;
button: number;
shiftKey: boolean;
altKey: boolean;
ctrlKey: boolean;
metaKey: boolean;
preventDefault(): void;
}
declare function shouldHandleClick(e: MouseEventLike): boolean;
declare function navigate(to: string, options?: NavigationOptions): Promise<boolean>;
interface NavigationOptions {
replace?: boolean;
scroll?: boolean;
data?: any;
}
declare type RenderFunction = (abortSignal: AbortSignal) => void | Promise<void>;
declare type NavigationListener = (navigation: NavigationState) => void;
interface NavigationState {
currentUrl: string;
pendingUrl?: string;
}
declare function addNavigationListener(listener: NavigationListener): void;
declare function removeNavigationListener(listener: NavigationListener): void;
declare function addNavigationBlocker(blocker: () => boolean | Promise<boolean>): void;
declare function removeNavigationBlocker(blocker: () => boolean | Promise<boolean>): void;
export { MouseEventLike, NavigationListener, NavigationOptions, NavigationState, RenderFunction, addNavigationBlocker, addNavigationListener, finalize, initialize, navigate, removeNavigationBlocker, removeNavigationListener, shouldHandleClick };