fix: 资源加载失败时自动刷新页面

- 添加路由错误处理,当动态导入模块失败时自动刷新页面
- 修复 assets 文件不存在时返回 404 错误
This commit is contained in:
2026-05-04 10:54:31 +08:00
parent 9937fbbae2
commit 16af684a32
2 changed files with 13 additions and 0 deletions
+7
View File
@@ -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))
})
+6
View File
@@ -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