Skip to content

Commit

Permalink
fix: white page when toggling between open and close in tabbar mode(/…
Browse files Browse the repository at this point in the history
…about?a=10)
  • Loading branch information
condorheroblog committed Dec 25, 2024
1 parent 36fb3e1 commit c9d9e96
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/layout/layout-tabbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,22 @@ export default function LayoutTabbar() {
useEffect(() => {
const activePath = location.pathname;
const normalizedPath = removeTrailingSlash(activePath);
// tabbarEnable 变量会导致本组件挂载和卸载,normalizedPath 可能与 activeKey 相同,增加判断防止 addTab 重复添加
if (normalizedPath !== activeKey) {
setActiveKey(normalizedPath);

setActiveKey(normalizedPath);
const routeTitle = currentRoute.handle?.title;

const routeTitle = currentRoute.handle?.title;

addTab(normalizedPath, {
key: normalizedPath,
// 保证 label 为 string 类型,存储到 sessionStorage。
label: isValidElement(routeTitle) ? routeTitle?.props?.children : routeTitle,
historyState: { search: location.search, hash: location.hash },
/* 登录之后跳转的默认路由,不可以关闭和拖拽 */
closable: normalizedPath !== import.meta.env.VITE_BASE_HOME_PATH,
draggable: normalizedPath !== import.meta.env.VITE_BASE_HOME_PATH,
});
addTab(normalizedPath, {
key: normalizedPath,
// 保证 label 为 string 类型,存储到 sessionStorage。
label: isValidElement(routeTitle) ? routeTitle?.props?.children : routeTitle,
historyState: { search: location.search, hash: location.hash },
/* 登录之后跳转的默认路由,不可以关闭和拖拽 */
closable: normalizedPath !== import.meta.env.VITE_BASE_HOME_PATH,
draggable: normalizedPath !== import.meta.env.VITE_BASE_HOME_PATH,
});
}
}, [location, currentRoute, setActiveKey, addTab]);

return (
Expand Down

0 comments on commit c9d9e96

Please sign in to comment.