Files
frontend/apps/common/features/src/entities/menu/lib/utils.ts
T

21 lines
474 B
TypeScript

import type { MenuRole } from "../model/menu-interface";
export const getCurrentMenu = (
menus: MenuRole[],
pathname: string,
): MenuRole | null => {
for (const menu of menus) {
if (
menu.urlPath !== "" &&
(menu.urlPath === pathname || pathname.startsWith(menu.urlPath))
)
return menu;
if (menu.children) {
const children = getCurrentMenu(menu.children, pathname);
if (children) return children;
}
}
return null;
};