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

22 lines
481 B
TypeScript

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