16 lines
450 B
TypeScript
16 lines
450 B
TypeScript
export const findMenuItemByPath = (items: any[], targetPath: string): any | null => {
|
|
for (const item of items || []) {
|
|
if (item?.to === targetPath) {
|
|
return item;
|
|
}
|
|
|
|
if (Array.isArray(item?.children) && item.children.length > 0) {
|
|
const found = findMenuItemByPath(item.children, targetPath);
|
|
if (found) {
|
|
return found;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}; |