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) {