fix: ensure URL paths start with process.env.APP_PUBLIC_PATH

This commit is contained in:
chenos 2025-01-09 18:14:17 +08:00
parent 7e5dedae45
commit 736aa9ee93
2 changed files with 13 additions and 4 deletions

View File

@ -20,12 +20,11 @@ export default defineConfig({
metas: [{ name: 'viewport', content: 'initial-scale=0.1' }],
links: [{ rel: 'stylesheet', href: `${appPublicPath}global.css` }],
headScripts: [
{
src: `${appPublicPath}browser-checker.js`,
},
{
content: isDevCmd
? ''
? `
window['__nocobase_public_path__'] = "${process.env.APP_PUBLIC_PATH || '/'}";
`
: `
window['__webpack_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
window['__nocobase_public_path__'] = '{{env.APP_PUBLIC_PATH}}';
@ -36,6 +35,9 @@ export default defineConfig({
window['__nocobase_ws_path__'] = '{{env.WS_PATH}}';
`,
},
{
src: `${appPublicPath}browser-checker.js`,
},
],
cacheDirectoryPath: process.env.APP_CLIENT_CACHE_DIR || `node_modules/.cache`,
outputPath: path.resolve(__dirname, '../dist/client'),

View File

@ -1,3 +1,10 @@
const basename = window['__nocobase_public_path__'] || '/';
let currentPath = window.location.pathname;
if (!currentPath.startsWith(basename)) {
let newPath = basename + (currentPath.startsWith('/') ? currentPath.slice(1) : currentPath);
let newUrl = window.location.origin + newPath + window.location.search + window.location.hash;
window.location.href = newUrl;
}
showLog = true;
function log(m) {
if (window.console && showLog) {