Skip to content

Commit

Permalink
Merge pull request #915 from chat2db/dev
Browse files Browse the repository at this point in the history
location
  • Loading branch information
shanhexi authored Dec 5, 2023
2 parents 497abbd + ed91f79 commit 6d4a0cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions chat2db-client/src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import Connection from './connection';
import Team from './team';
import Setting from '@/blocks/Setting';

// ----- utils -----
import { generateUrl } from '@/utils/url';

import styles from './index.less';
import { useUpdateEffect } from '@/hooks';

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

useEffect(() => {
handleInitPage();
Expand All @@ -88,7 +93,7 @@ function MainPage() {
navConfig[activeIndex].isLoad = true;
setNavConfig([...navConfig]);
// 桌面端跳转这里应该要换TODO:
const href = window.location.origin + '/' + activeNavKey;
const href = generateUrl(activeNavKey);
window.history.pushState({}, '', href);
}
}, [activeNavKey]);
Expand Down
13 changes: 13 additions & 0 deletions chat2db-client/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,16 @@ export function formatParams(obj: { [key: string]: any }) {
});
return params.toString();
}

/**
* 生成url
* @param key
* @returns
*/

export function generateUrl(key: string) {
if (__ENV__ === 'desktop') {
return window.location.href + '/#/' + key;
}
return window.location.origin + '/' + key;
}

0 comments on commit 6d4a0cb

Please sign in to comment.