14 lines
427 B
TypeScript
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 '';
|
|
};
|