From bc87184f846b3eb89e38b1f6934d50123a0287dc Mon Sep 17 00:00:00 2001 From: engigu Date: Tue, 13 Jan 2026 22:03:21 +0800 Subject: [PATCH] fix: url prefix page redirect --- internal/router/router.go | 7 +++---- web/index.html | 14 ++------------ web/vite.config.ts | 4 +++- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/internal/router/router.go b/internal/router/router.go index 69458fd..4a36f45 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -246,10 +246,9 @@ func Setup(c *Controllers) *gin.Engine { html := string(data) - // 在第一个 script 标签中注入配置 - // 这样可以确保在资源加载前就设置好 base 标签 - configScript := `window.__BASE_URL__ = "` + urlPrefix + `"; window.__API_VERSION__ = "/api/v1";` - html = strings.Replace(html, "// 后端会在这里注入:", configScript + "\n //", 1) + // 注入配置变量供前端使用(API 调用和路由) + configScript := `` + html = strings.Replace(html, "", configScript+"", 1) ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate") ctx.Data(200, "text/html; charset=utf-8", []byte(html)) diff --git a/web/index.html b/web/index.html index c9497ac..346ed0f 100644 --- a/web/index.html +++ b/web/index.html @@ -2,22 +2,12 @@ - - - +
- + diff --git a/web/vite.config.ts b/web/vite.config.ts index 95c1844..bad01c6 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -19,5 +19,7 @@ export default defineConfig({ } } }, - base: '/' + // 使用相对路径,这样动态导入的模块也会使用相对路径 + // 浏览器会根据当前页面 URL 解析相对路径 + base: './' })