Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit ef79854

Browse files
committed
fix(context): fix reroute loop
1 parent 0bc3047 commit ef79854

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

‎packages/console-utils/xconsole-context/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/xconsole-context",
3-
"version": "2.5.3",
3+
"version": "2.5.4",
44
"main": "lib/index.js",
55
"module": "es/index.js",
66
"types": "lib/index.d.ts",

‎packages/console-utils/xconsole-context/src/region/reroute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { IConsoleContextRegionProp } from '../types/index';
77
* @param match
88
* @returns
99
*/
10-
const hasRegionId = (match: IMatch) => {
10+
exportconst hasRegionId = (match: IMatch) => {
1111
// eslint-disable-next-line no-prototype-builtins
1212
return match.params && match.params.hasOwnProperty('regionId');
1313
};

‎packages/console-utils/xconsole-context/src/region/useRegion.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useLayoutEffect, useState, useContext, useCallback, useMemo } from 'react';
1+
import { useEffect, useLayoutEffect, useState, useContext, useCallback, useMemo,useRef } from 'react';
22
import { matchPath } from 'react-router-dom';
33

44
import ConsoleBaseFallback from '../console/ConsoleBase';
@@ -39,6 +39,11 @@ export default (props: IConsoleContextRegionProp<{regionId?: string}>): Region =
3939
);
4040
const regionContext = useContext(RegionContext);
4141
const consoleBase = useMemo(() => passInConsoleBase || ConsoleBaseFallback, [passInConsoleBase]);
42+
const matchRef = useRef(match);
43+
const locationRef = useRef(location);
44+
45+
matchRef.current = match;
46+
locationRef.current = location;
4247

4348
/**
4449
* 计算更新 regionId 状态,也设置临时变量中的 ID
@@ -63,11 +68,13 @@ export default (props: IConsoleContextRegionProp<{regionId?: string}>): Region =
6368
* 如果是 region 路由,且 regionId 变化时重定向
6469
*/
6570
const rerouteIfNeed = useCallback((regionId: string) => {
66-
reroute({ history, match, location }, regionId, historyAction);
71+
reroute({
72+
history,
73+
match: matchRef.current,
74+
location: locationRef.current,
75+
}, regionId, historyAction);
6776
}, [
6877
history,
69-
match,
70-
location,
7178
historyAction,
7279
]);
7380

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /