import { useLocation } from 'react-router-dom' ; import { keyBy } from 'lodash' ; import { useMemo } from 'react' ; import type { MlRoute } from './router' ; export const useActiveRoute = ( routesList ) : MlRoute => { const { pathname } = useLocation ( ) ; const routesMap = useMemo ( ( ) => keyBy ( routesList , 'path' ) , [ ] ) ; const activeRoute = useMemo ( ( ) => routesMap [ pathname ] , [ pathname ] ) ; return activeRoute ?? routesMap [ '/overview' ] ; } ;