import { History } from 'history' ; import { useLayoutEffect } from 'react' ; import { createUrlTracker } from '../../../opensearch_dashboards_utils/public/' ; param key param history param shouldRestoreUrl param storage export function useUrlTracker ( key , history , shouldRestoreUrl = ( ) => true , storage = sessionStorage ) { useLayoutEffect ( ( ) => { const urlTracker = createUrlTracker ( key , storage ) ; const urlToRestore = urlTracker . getTrackedUrl ( ) ; if ( urlToRestore && shouldRestoreUrl ( urlToRestore ) ) { history . replace ( urlToRestore ) ; } const stopTrackingUrl = urlTracker . startTrackingUrl ( history ) ; return ( ) => { stopTrackingUrl ( ) ; } ; } , [ key , history ] ) ; }