refactor: 重命名 basename 模块为 dynamic-name,添加 URL hash 参数支持

This commit is contained in:
xiongxiao
2026-03-19 20:26:27 +08:00
committed by cnb
parent 6b72054525
commit 48b915c4a4
3 changed files with 21 additions and 1 deletions

View File

@@ -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({

View File

@@ -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
}

View File

@@ -246,6 +246,10 @@ export const useCodeGraphStore = create<State>()((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) {