From 32b4b944cc047167ac39be574570a2a2f209ce55 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 8 May 2025 22:42:20 +0800 Subject: [PATCH] fix remoteEntry url --- src/utils/federationLoader.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/federationLoader.ts b/src/utils/federationLoader.ts index 14663d39..1b368373 100644 --- a/src/utils/federationLoader.ts +++ b/src/utils/federationLoader.ts @@ -45,8 +45,18 @@ async function fetchRemoteModules(): Promise { * @param modules 远程模块列表 */ function injectRemoteModule(module: RemoteModule): void { + // 从浏览器地址栏获取当前地址前缀 + const baseUrl = new URL(window.location.href) + // 环境变量 + let apiBase = import.meta.env.VITE_API_BASE_URL + if (apiBase.startsWith('/')) { + apiBase = apiBase.slice(1) + } + if (apiBase.endsWith('/')) { + apiBase = apiBase.slice(0, -1) + } __federation_method_setRemote(module.id, { - url: () => Promise.resolve(`${import.meta.env.VITE_API_BASE_URL}/${module.url}`), + url: () => Promise.resolve(`${baseUrl.origin}/${apiBase}${module.url}`), format: 'esm', from: 'vite', })