From 16af684a32f2b74753d45ce521b1551d205f45ff Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 May 2026 10:54:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B5=84=E6=BA=90=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加路由错误处理,当动态导入模块失败时自动刷新页面 - 修复 assets 文件不存在时返回 404 错误 --- backend/cmd/main.go | 7 +++++++ frontend/src/router/index.ts | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 21d9197..ba53593 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -262,6 +262,13 @@ func setupEmbeddedFrontend(r *gin.Engine) { } r.GET("/assets/*filepath", func(c *gin.Context) { + filepath := strings.TrimPrefix(c.Request.URL.Path, "/assets/") + file, err := distFS.Open(filepath) + if err != nil { + c.JSON(404, gin.H{"error": "asset not found"}) + return + } + file.Close() c.Header("Cache-Control", "public, max-age=31536000, immutable") c.FileFromFS(c.Request.URL.Path, http.FS(distFS)) }) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 2602ef7..fa2796c 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -13,6 +13,12 @@ const router = createRouter({ }, }) +router.onError((error) => { + if (error.message.includes('Failed to fetch dynamically imported module')) { + window.location.reload() + } +}) + createRouterGuard(router) export default router