2023-12-12 12:53:20 +00:00
|
|
|
import { useRouterConfig } from '../../pages/client-router';
|
2023-09-15 12:36:08 +00:00
|
|
|
import { matchRoutes, useLocation } from 'react-router-dom';
|
|
|
|
|
|
|
|
export const useGetCurrentRouteId = () => {
|
|
|
|
const location = useLocation();
|
2023-12-12 12:53:20 +00:00
|
|
|
const matches = matchRoutes(useRouterConfig(), location);
|
2023-09-20 20:28:34 +00:00
|
|
|
const lastRoute = matches ? matches[matches.length - 1] : undefined;
|
2023-09-15 12:36:08 +00:00
|
|
|
if (lastRoute) {
|
2023-09-20 20:28:34 +00:00
|
|
|
const id = lastRoute.route.id;
|
2023-09-15 12:36:08 +00:00
|
|
|
return id || '';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|