diff --git a/packages/core/app/client/.umirc.ts b/packages/core/app/client/.umirc.ts index 1eceaf186f..cf0eb89dd8 100644 --- a/packages/core/app/client/.umirc.ts +++ b/packages/core/app/client/.umirc.ts @@ -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'), diff --git a/packages/core/app/client/public/browser-checker.js b/packages/core/app/client/public/browser-checker.js index 0ae7fd8996..6a14d0d6e5 100644 --- a/packages/core/app/client/public/browser-checker.js +++ b/packages/core/app/client/public/browser-checker.js @@ -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) {