vega-frontend-monorepo/apps/trading/lib/hooks/use-get-current-route-id.ts

14 lines
427 B
TypeScript
Raw Normal View History

import { useRouterConfig } from '../../pages/client-router';
import { matchRoutes, useLocation } from 'react-router-dom';
export const useGetCurrentRouteId = () => {
const location = useLocation();
const matches = matchRoutes(useRouterConfig(), location);
const lastRoute = matches ? matches[matches.length - 1] : undefined;
if (lastRoute) {
const id = lastRoute.route.id;
return id || '';
}
return '';
};