This is an automated email from the ASF dual-hosted git repository.

dengliming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 76878257 fix: prefer Home for the base redirect (#689)
76878257 is described below

commit 76878257b063637835b38f6c7e65eb49b8cb6040
Author: Carlos Acosta <[email protected]>
AuthorDate: Sun Sep 27 00:30:28 2026 -0500

    fix: prefer Home for the base redirect (#689)
    
    Co-authored-by: Aeontra <aeontra@localhost>
---
 src/layouts/BasicLayout.js  | 10 +++++-----
 src/utils/AuthRoute.js      | 10 ++++++++++
 src/utils/AuthRoute.test.js | 34 +++++++++++++++++++++++++++++++++-
 3 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js
index 188bac4b..0aae6688 100644
--- a/src/layouts/BasicLayout.js
+++ b/src/layouts/BasicLayout.js
@@ -29,7 +29,10 @@ import GlobalHeader from "../components/GlobalHeader";
 import SiderMenu from "../components/SiderMenu";
 import NotFound from "../routes/Exception/404";
 import { getRoutes } from "../utils/utils";
-import AuthRoute, { checkMenuAuth, getAuthMenus } from "../utils/AuthRoute";
+import AuthRoute, {
+  getAuthMenus,
+  getBaseRedirectPath,
+} from "../utils/AuthRoute";
 import { getMenuData } from "../common/menu";
 import logo from "../assets/logo.svg";
 import TitleLogo from "../assets/TitleLogo.svg";
@@ -199,10 +202,7 @@ class BasicLayout extends React.PureComponent {
       window.history.replaceState(null, "redirect", urlParams.href);
     } else {
       const { routerData, permissions } = this.props;
-      // get the first authorized route path in routerData
-      return Object.keys(routerData).find(
-        (item) => checkMenuAuth(item, permissions) && item !== "/",
-      );
+      return getBaseRedirectPath(routerData, permissions);
     }
     return redirect;
   };
diff --git a/src/utils/AuthRoute.js b/src/utils/AuthRoute.js
index 025fe810..d5c94404 100644
--- a/src/utils/AuthRoute.js
+++ b/src/utils/AuthRoute.js
@@ -87,6 +87,16 @@ export function checkMenuAuth(routeUrl, permissions) {
   }
 }
 
+export function getBaseRedirectPath(routerData, permissions) {
+  if (routerData["/home"] && checkMenuAuth("/home", permissions)) {
+    return "/home";
+  }
+
+  return Object.keys(routerData).find(
+    (route) => route !== "/" && checkMenuAuth(route, permissions),
+  );
+}
+
 /**
  *  get all authorized menus
  *  if authMenusCache is not empty,return from cache,
diff --git a/src/utils/AuthRoute.test.js b/src/utils/AuthRoute.test.js
index 7948c388..9d137211 100644
--- a/src/utils/AuthRoute.test.js
+++ b/src/utils/AuthRoute.test.js
@@ -15,7 +15,12 @@
  * limitations under the License.
  */
 
-import { checkMenuAuth, getAuthMenus, resetAuthMenuCache } from "./AuthRoute";
+import {
+  checkMenuAuth,
+  getAuthMenus,
+  getBaseRedirectPath,
+  resetAuthMenuCache,
+} from "./AuthRoute";
 
 jest.mock("./IntlUtils", () => ({ getIntlContent: (key) => key }));
 
@@ -50,6 +55,33 @@ it("matches a plugin instance against its normalized 
permission route", () => {
   expect(checkMenuAuth("/plug/42/dubbo", permissions)).toBe(false);
 });
 
+it("prefers Home over earlier authorized routes", () => {
+  const routerData = {
+    "/": {},
+    "/plug/Mcp/mcpServer": {},
+    "/home": {},
+    "/system/user": {},
+  };
+  const permissions = {
+    menu: [{ url: "/plug/mcpServer" }, { url: "/system/user" }],
+  };
+
+  expect(getBaseRedirectPath(routerData, permissions)).toBe("/home");
+});
+
+it("falls back to the first authorized route when Home is unavailable", () => {
+  const routerData = {
+    "/": {},
+    "/system/user": {},
+    "/system/role": {},
+  };
+  const permissions = {
+    menu: [{ url: "/system/role" }],
+  };
+
+  expect(getBaseRedirectPath(routerData, permissions)).toBe("/system/role");
+});
+
 it("uses the new namespace's permissions even when a previous menu was 
cached", () => {
   const first = { menu: [{ url: "/system/user" }] };
   const second = { menu: [{ url: "/system/role" }] };

Reply via email to