|
|
|
@ -14,14 +14,16 @@ const { pathname, search } = useLocation();
@@ -14,14 +14,16 @@ const { pathname, search } = useLocation();
|
|
|
|
|
// useEffect 监听路由是否发生变化 |
|
|
|
|
useEffect(() => addTabItem(pathname, search), [pathname, search]); |
|
|
|
|
|
|
|
|
|
// 记录路由的 State |
|
|
|
|
// 记录路由的 State,Tab列表 |
|
|
|
|
const [tabList, setTabList] = useState( |
|
|
|
|
[{ name: "Dashboard", path: "/", search: "" }] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 路由添加函数 |
|
|
|
|
const addTabItem = (path, search) => { |
|
|
|
|
// 判断路由是不是已经存在于 State 中,不存在就添加到 Tab 列表中 |
|
|
|
|
if (tabList.findIndex((item) => item.path === path) === -1) { |
|
|
|
|
// 这里主要是为了保存 |
|
|
|
|
const flattenList = flattenArray(routerConfig); |
|
|
|
|
const routerIndex = flattenList.findIndex((item) => { |
|
|
|
|
item.path === path |
|
|
|
|