Skip to content

Commit c686b70

Browse files
authored
Merge pull request #82 from warjiang/fix/i18n-breadcrumb
fix: new method for generate breadcrumbs
2 parents 650ef60 + 3a4711a commit c686b70

File tree

1 file changed

+24
-10
lines changed
  • ui/apps/dashboard/src/components/panel

1 file changed

+24
-10
lines changed

ui/apps/dashboard/src/components/panel/index.tsx

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC, ReactNode, useMemo } from 'react';
22
import { useMatches } from 'react-router-dom';
33
import { Breadcrumb } from 'antd';
4-
import { IRouteObjectHandle } from '@/routes/route.tsx';
4+
import { getRoutes, IRouteObjectHandle } from '@/routes/route.tsx';
55
import * as React from 'react';
66

77
interface IPanelProps {
@@ -21,15 +21,29 @@ const Panel: FC<IPanelProps> = (props) => {
2121
const matches = useMatches();
2222
const breadcrumbs = useMemo(() => {
2323
if (!matches || matches.length === 0) return [] as MenuItem[];
24-
return matches
25-
.filter((m) => Boolean(m.handle))
26-
.map((m) => {
27-
const { isPage, sidebarName } = m.handle as IRouteObjectHandle;
28-
const pathname = m.pathname;
29-
return {
30-
title: isPage && pathname ? <a>{sidebarName}</a> : sidebarName,
31-
};
32-
}) as MenuItem[];
24+
const filteredMatches = matches.filter((m) => Boolean(m.handle));
25+
let idx = 0;
26+
let ptr = getRoutes()[0];
27+
const menuItems: MenuItem[] = [];
28+
while (idx < filteredMatches.length) {
29+
const { isPage, sidebarKey: _sideBarKey } = filteredMatches[idx]
30+
.handle as IRouteObjectHandle;
31+
for (let i = 0; ptr.children && i < ptr.children.length; i++) {
32+
if (ptr.children[i].handle?.sidebarKey === _sideBarKey) {
33+
menuItems.push({
34+
title:
35+
isPage && filteredMatches[idx].pathname ? (
36+
<a>{ptr.children[i].handle?.sidebarName}</a>
37+
) : (
38+
ptr.children[i].handle?.sidebarName
39+
),
40+
});
41+
ptr = ptr.children[i];
42+
}
43+
}
44+
idx++;
45+
}
46+
return menuItems;
3347
}, [matches]);
3448
return (
3549
<div className="w-full h-full px-[30px] py-[20px] box-border bg-[#FAFBFC]">

0 commit comments

Comments
 (0)