|
@@ -1,4 +1,4 @@
|
|
-import { FC, useCallback, useState } from "react";
|
|
|
|
|
|
+import { FC, useCallback, useMemo, useState } from "react";
|
|
import style from "./index.module.scss";
|
|
import style from "./index.module.scss";
|
|
import { App, Avatar, Breadcrumb, Button, Popover } from "antd";
|
|
import { App, Avatar, Breadcrumb, Button, Popover } from "antd";
|
|
import { Header } from "antd/es/layout/layout";
|
|
import { Header } from "antd/es/layout/layout";
|
|
@@ -24,6 +24,8 @@ const generateBreadcrumb = (
|
|
title: string;
|
|
title: string;
|
|
href?: string;
|
|
href?: string;
|
|
}[] => {
|
|
}[] => {
|
|
|
|
+ if (!pathname || !child.length) return [];
|
|
|
|
+
|
|
const breadcrumb = [];
|
|
const breadcrumb = [];
|
|
const paths = pathname.split("/").filter((path) => path !== "");
|
|
const paths = pathname.split("/").filter((path) => path !== "");
|
|
let currentPath = "";
|
|
let currentPath = "";
|
|
@@ -31,6 +33,7 @@ const generateBreadcrumb = (
|
|
for (let i = 0; i < paths.length; i++) {
|
|
for (let i = 0; i < paths.length; i++) {
|
|
currentPath += `/${paths[i]}`;
|
|
currentPath += `/${paths[i]}`;
|
|
const item = findRouteByPath(child, currentPath);
|
|
const item = findRouteByPath(child, currentPath);
|
|
|
|
+
|
|
if (item) {
|
|
if (item) {
|
|
breadcrumb.push({
|
|
breadcrumb.push({
|
|
title: item.title,
|
|
title: item.title,
|
|
@@ -48,7 +51,10 @@ const generateBreadcrumb = (
|
|
export const LayoutHeader: FC<LayoutHeaderProps> = ({ menuData }) => {
|
|
export const LayoutHeader: FC<LayoutHeaderProps> = ({ menuData }) => {
|
|
const { modal } = App.useApp();
|
|
const { modal } = App.useApp();
|
|
const location = useLocation();
|
|
const location = useLocation();
|
|
- const breadcrumbItems = generateBreadcrumb(location.pathname, menuData);
|
|
|
|
|
|
+ const breadcrumbItems = useMemo(
|
|
|
|
+ () => generateBreadcrumb(location.pathname, menuData),
|
|
|
|
+ [location, menuData]
|
|
|
|
+ );
|
|
const [resetPwdModalVisible, setResetPwdModalVisible] = useState(false);
|
|
const [resetPwdModalVisible, setResetPwdModalVisible] = useState(false);
|
|
const { userInfo } = useSelector<RootState, RootState["base"]>(
|
|
const { userInfo } = useSelector<RootState, RootState["base"]>(
|
|
(state) => state.base
|
|
(state) => state.base
|