From 48b915c4a4e172fd63281b85ff51311bc491790c Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Thu, 19 Mar 2026 20:26:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E5=91=BD=E5=90=8D=20basen?= =?UTF-8?q?ame=20=E6=A8=A1=E5=9D=97=E4=B8=BA=20dynamic-name=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20URL=20hash=20=E5=8F=82=E6=95=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.tsx | 2 +- src/modules/dynamic-name.ts | 16 ++++++++++++++++ src/pages/code-graph/store/index.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/modules/dynamic-name.ts diff --git a/src/main.tsx b/src/main.tsx index f876785..1b77efd 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,7 +2,7 @@ import ReactDOM from 'react-dom/client' import { RouterProvider, createRouter } from '@tanstack/react-router' import { routeTree } from './routeTree.gen' import './index.css' -import { getDynamicBasename } from './modules/basename' +import { getDynamicBasename } from './modules/dynamic-name.ts' import './agents/index.ts'; // Set up a Router instance const router = createRouter({ diff --git a/src/modules/dynamic-name.ts b/src/modules/dynamic-name.ts new file mode 100644 index 0000000..85e8451 --- /dev/null +++ b/src/modules/dynamic-name.ts @@ -0,0 +1,16 @@ +import { basename } from "./basename" + +// 动态计算 basename,根据当前 URL 路径 +export const getDynamicBasename = (): string => { + const path = window.location.pathname + const origin = window.location.origin + const [user, key, id] = path.split('/').filter(Boolean) + if (key === 'v1' && id) { + return `/${user}/v1/${id}` + } + if (origin.includes('cnb.kevisual.cn')) { + return '/'; + } + // 默认使用构建时的 basename + return basename +} diff --git a/src/pages/code-graph/store/index.ts b/src/pages/code-graph/store/index.ts index 9391796..c33e75e 100644 --- a/src/pages/code-graph/store/index.ts +++ b/src/pages/code-graph/store/index.ts @@ -246,6 +246,10 @@ export const useCodeGraphStore = create()((set, get) => ({ if (isCNB()) { url = `/client/router`; } + const urlFromHash = new URLSearchParams(window.location.hash.slice(1)).get('url'); + if (urlFromHash) { + url = urlFromHash; + } set({ url }); const load = opts.load ?? true; if (load) {