/** * Represents the type of navigation that occurred. */ export type NavigationLocationchangeEventType = 'init' | 'pop' | 'push' | 'replace'; /** * Event detail payload dispatched when navigation location changes. */ export type NavigationLocationchangeEventDetail = { /** * The type of navigation that triggered the event */ type: NavigationLocationchangeEventType; /** * The current URL after navigation */ url: string; }; /** * Patches the browser's History API to dispatch custom events when navigation occurs. * This function intercepts `pushState`, `replaceState`, and `popstate` events to provide * a unified interface for listening to navigation changes. * @param options - Configuration options for the history patching * @param options.eventName - The name of the custom event to dispatch on navigation changes * @param options.signal - Optional AbortSignal to control the lifecycle of the patching * @returns A dispose function that restores the original History API methods and removes event listeners * @example * // Example 1. Basic usage * const dispose = patchHistory({eventName: 'locationchange'}) * // Listen for navigation changes * window.addEventListener('locationchange', (event) => { * console.log(`Navigation: ${event.detail.type} to ${event.detail.url}`); * }) * // Clean up when done * dispose() * * // Example 2. Usage with AbortSignal * const controller = new AbortController() * patchHistory({eventName: 'locationchange', signal: controller.signal}) * window.addEventListener('locationchange', (event) => { * console.log(`Navigation: ${event.detail.type} to ${event.detail.url}`); * }) * // Automatically dispose when signal is aborted * controller.abort() */ export declare const patchHistory: (options: { eventName: string; signal?: AbortSignal; }) => () => void; //# sourceMappingURL=patchHistory.d.ts.map