refactor: 重命名 basename 模块为 dynamic-name,添加 URL hash 参数支持
This commit is contained in:
@@ -2,7 +2,7 @@ import ReactDOM from 'react-dom/client'
|
|||||||
import { RouterProvider, createRouter } from '@tanstack/react-router'
|
import { RouterProvider, createRouter } from '@tanstack/react-router'
|
||||||
import { routeTree } from './routeTree.gen'
|
import { routeTree } from './routeTree.gen'
|
||||||
import './index.css'
|
import './index.css'
|
||||||
import { getDynamicBasename } from './modules/basename'
|
import { getDynamicBasename } from './modules/dynamic-name.ts'
|
||||||
import './agents/index.ts';
|
import './agents/index.ts';
|
||||||
// Set up a Router instance
|
// Set up a Router instance
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|||||||
16
src/modules/dynamic-name.ts
Normal file
16
src/modules/dynamic-name.ts
Normal 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
|
||||||
|
}
|
||||||
@@ -246,6 +246,10 @@ export const useCodeGraphStore = create<State>()((set, get) => ({
|
|||||||
if (isCNB()) {
|
if (isCNB()) {
|
||||||
url = `/client/router`;
|
url = `/client/router`;
|
||||||
}
|
}
|
||||||
|
const urlFromHash = new URLSearchParams(window.location.hash.slice(1)).get('url');
|
||||||
|
if (urlFromHash) {
|
||||||
|
url = urlFromHash;
|
||||||
|
}
|
||||||
set({ url });
|
set({ url });
|
||||||
const load = opts.load ?? true;
|
const load = opts.load ?? true;
|
||||||
if (load) {
|
if (load) {
|
||||||
|
|||||||
Reference in New Issue
Block a user