fix: url prefix page redirect
This commit is contained in:
@@ -243,8 +243,16 @@ func Setup(c *Controllers) *gin.Engine {
|
|||||||
ctx.String(500, "index.html not found")
|
ctx.String(500, "index.html not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html := string(data)
|
||||||
|
|
||||||
|
// 只注入配置变量,不做字符串替换
|
||||||
|
// 前端会使用这些变量来构建正确的路径
|
||||||
|
configScript := `<script>window.__BASE_URL__ = "` + urlPrefix + `"; window.__API_VERSION__ = "/api/v1";</script>`
|
||||||
|
html = strings.Replace(html, "</head>", configScript+"</head>", 1)
|
||||||
|
|
||||||
ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
ctx.Data(200, "text/html; charset=utf-8", data)
|
ctx.Data(200, "text/html; charset=utf-8", []byte(html))
|
||||||
})
|
})
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|||||||
@@ -5,6 +5,17 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
|
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title></title>
|
<title></title>
|
||||||
|
<script>
|
||||||
|
// 在资源加载前设置 base 标签
|
||||||
|
(function() {
|
||||||
|
var baseUrl = window.__BASE_URL__;
|
||||||
|
if (baseUrl) {
|
||||||
|
var base = document.createElement('base');
|
||||||
|
base.href = baseUrl + '/';
|
||||||
|
document.head.appendChild(base);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user