From 2cb404846ed8e6a0e80adf57a893b6bbc2249fc8 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Wed, 18 Feb 2026 21:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20basename=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=20basename=20=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=20main.tsx=20=E4=B8=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=AF=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.tsx | 4 ++-- src/modules/basename.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index d8e0544..e95e756 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,12 +2,12 @@ import ReactDOM from 'react-dom/client' import { RouterProvider, createRouter } from '@tanstack/react-router' import { routeTree } from './routeTree.gen' import './index.css' -import { basename } from './modules/basename' +import { getDynamicBasename } from './modules/basename' // Set up a Router instance const router = createRouter({ routeTree, - basepath: basename, + basepath: getDynamicBasename(), defaultPreload: 'intent', scrollRestoration: true, }) diff --git a/src/modules/basename.ts b/src/modules/basename.ts index df380e1..0516610 100644 --- a/src/modules/basename.ts +++ b/src/modules/basename.ts @@ -8,4 +8,15 @@ export const wrapBasename = (path: string) => { } else { return path; } +} + +// 动态计算 basename,根据当前 URL 路径 +export const getDynamicBasename = (): string => { + const path = window.location.pathname + const [user, key, id] = path.split('/').filter(Boolean) + if (key === 'v1' && id) { + return `/${user}/v1/${id}` + } + // 默认使用构建时的 basename + return basename } \ No newline at end of file