Skip to content

Commit ed91f79

Browse files
committed
location
1 parent 55cd975 commit ed91f79

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

chat2db-client/src/pages/main/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import Connection from './connection';
2525
import Team from './team';
2626
import Setting from '@/blocks/Setting';
2727

28+
// ----- utils -----
29+
import { generateUrl } from '@/utils/url';
30+
2831
import styles from './index.less';
2932
import { useUpdateEffect } from '@/hooks';
3033

@@ -68,7 +71,9 @@ function MainPage() {
6871
const [navConfig, setNavConfig] = useState<INavItem[]>(initNavConfig);
6972
const [userInfo, setUserInfo] = useState<ILoginUser>();
7073
const mainPageActiveTab = useMainStore((state) => state.mainPageActiveTab);
71-
const [activeNavKey, setActiveNavKey] = useState<string>(window.location.pathname.split('/')[1] || mainPageActiveTab);
74+
const [activeNavKey, setActiveNavKey] = useState<string>(
75+
__ENV__ === 'desktop' ? mainPageActiveTab : window.location.pathname.split('/')[1] || mainPageActiveTab,
76+
);
7277

7378
useEffect(() => {
7479
handleInitPage();
@@ -88,7 +93,7 @@ function MainPage() {
8893
navConfig[activeIndex].isLoad = true;
8994
setNavConfig([...navConfig]);
9095
// 桌面端跳转这里应该要换TODO:
91-
const href = window.location.origin + '/' + activeNavKey;
96+
const href = generateUrl(activeNavKey);
9297
window.history.pushState({}, '', href);
9398
}
9499
}, [activeNavKey]);

chat2db-client/src/utils/url.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ export function formatParams(obj: { [key: string]: any }) {
7373
});
7474
return params.toString();
7575
}
76+
77+
/**
78+
* 生成url
79+
* @param key
80+
* @returns
81+
*/
82+
83+
export function generateUrl(key: string) {
84+
if (__ENV__ === 'desktop') {
85+
return window.location.href + '/#/' + key;
86+
}
87+
return window.location.origin + '/' + key;
88+
}

0 commit comments

Comments
 (0)