vega-frontend-monorepo/apps/trading/lib/hooks/use-get-current-route-id.ts
2023-12-12 13:53:20 +01:00

14 lines
427 B
TypeScript

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 '';
};