32 lines
631 B
TypeScript
32 lines
631 B
TypeScript
|
|
import { MenuItem } from "../_";
|
||
|
|
|
||
|
|
export function findMenu(menus: MenuItem[], pathname: string) {
|
||
|
|
if (!menus) {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
for (const m1 of menus) {
|
||
|
|
if (m1.path === pathname) {
|
||
|
|
return [m1.id];
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m1.children && m1.children.length) {
|
||
|
|
for (const m2 of m1.children) {
|
||
|
|
if (m2.path === pathname) {
|
||
|
|
return [m1.id, m2.id];
|
||
|
|
}
|
||
|
|
|
||
|
|
if (m2.children && m2.children.length) {
|
||
|
|
for (const m3 of m2.children) {
|
||
|
|
if (m3.path === pathname) {
|
||
|
|
return [m1.id, m2.id, m3.id];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return [];
|
||
|
|
}
|