@raisenow/tamaro-core
    Preparing search index...
    • 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.

      Parameters

      • options: { eventName: string; signal?: AbortSignal }

        Configuration options for the history patching

        • eventName: string

          The name of the custom event to dispatch on navigation changes

        • Optionalsignal?: AbortSignal

          Optional AbortSignal to control the lifecycle of the patching

      Returns () => void

      A dispose function that restores the original History API methods and removes event listeners

      // 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()