Skip to content

Commit 58d1feb

Browse files
committed
fix(projects): Fixed redirection when switching roles & init tab no cache
1 parent 32628df commit 58d1feb

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

packages/simple-router/src/router.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-nocheck
13
import { createBrowserRouter, createHashRouter, createMemoryRouter } from 'react-router-dom';
24
import type { Location, RouteObject } from 'react-router-dom';
35
import type { ElegantConstRoute } from '@ohh-889/react-auto-route';

src/hooks/common/login.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export function useLogin() {
1919

2020
if (userName) {
2121
await dispatch(initAuthRoute());
22-
await redirectFromLogin(redirect);
22+
23+
if (redirect) {
24+
await redirectFromLogin(redirect);
25+
}
26+
2327
window.$notification?.success({
2428
message: t('page.login.common.loginSuccess'),
2529
description: t('page.login.common.welcomeBack', { userName })

src/hooks/common/routerPush.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface RouterPushOptions {
1515
export function useRouterPush() {
1616
const router = useRouter();
1717

18+
const route = useRoute();
19+
1820
const [searchParams] = useSearchParams();
1921

2022
const routerPush = router.push;
@@ -77,7 +79,7 @@ export function useRouterPush() {
7779

7880
const options: RouterPushOptions = {};
7981

80-
const redirect = redirectUrl || router.currentRoute.fullPath;
82+
const redirect = redirectUrl || route.fullPath;
8183

8284
options.query = {
8385
redirect
@@ -92,7 +94,7 @@ export function useRouterPush() {
9294
* @param module
9395
*/
9496
async function toggleLoginModule(module: UnionKey.LoginModule) {
95-
const query = router.currentRoute.query as Record<string, string>;
97+
const query = route.query as Record<string, string>;
9698

9799
return routerPushByKey(`login_${module}`, { query });
98100
}

src/layouts/modules/global-tab/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useUpdateEffect } from 'ahooks';
55
import DarkModeContainer from '@/components/stateless/common/DarkModeContainer';
66
import BetterScroll from '@/components/stateless/custom/BetterScroll';
77
import { getDarkMode, getThemeSettings } from '@/store/slice/theme';
8-
import { addTabByRoute, getActiveTabId, isTabRetain, removeTab, selectAllTabs } from '@/store/slice/tab';
8+
import { addTabByRoute, getActiveTabId, initTabStore, isTabRetain, removeTab, selectAllTabs } from '@/store/slice/tab';
99
import {
1010
getFullContent,
1111
getIsMobile,
@@ -126,6 +126,10 @@ const GlobalTab = memo(() => {
126126
}
127127
});
128128

129+
useLayoutEffect(() => {
130+
dispatch(initTabStore());
131+
}, [dispatch]);
132+
129133
return (
130134
<DarkModeContainer className="size-full flex-y-center px-16px shadow-tab">
131135
<div

src/pages/function/toggle-auth/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ export function Component() {
9292

9393
await toLogin({ userName: account.userName, password: account.password }, false);
9494

95-
const routeNames = router.getAllRouteNames();
96-
97-
dispatch(initTabStore(routeNames));
95+
dispatch(initTabStore());
9896

9997
endLoading();
10098

src/store/slice/tab/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,15 @@ export const selectAllTabs = createSelector([getTabs, getHomeTab], (tabs, homeTa
107107
*
108108
* @param currentRoute Current route
109109
*/
110-
export const initTabStore =
111-
(routeNames: string[]): AppThunk =>
112-
(dispatch, getState) => {
113-
const storageTabs = localStg.get('globalTabs');
114-
const themeSettings = getThemeSettings(getState());
115-
if (themeSettings.tab.cache && storageTabs) {
116-
const tabs = extractTabsByAllRoutes(routeNames, storageTabs);
117-
dispatch(setTabs(tabs));
118-
}
119-
};
110+
export const initTabStore = (): AppThunk => (dispatch, getState) => {
111+
const storageTabs = localStg.get('globalTabs');
112+
const themeSettings = getThemeSettings(getState());
113+
114+
if (themeSettings.tab.cache && storageTabs) {
115+
const tabs = extractTabsByAllRoutes(router.getAllRouteNames(), storageTabs);
116+
dispatch(setTabs(tabs));
117+
}
118+
};
120119

121120
/**
122121
* Remove tab
@@ -201,6 +200,7 @@ export const cacheTabs = (): AppThunk => (_, getState) => {
201200
const themeSettings = getThemeSettings(getState());
202201
if (!themeSettings.tab.cache) return;
203202
const tabs = getTabs(getState());
203+
204204
localStg.set('globalTabs', tabs);
205205
};
206206

0 commit comments

Comments
 (0)