diff --git a/packages/uni-h5-vite/src/plugins/manifestJson.ts b/packages/uni-h5-vite/src/plugins/manifestJson.ts index 3f27399effc6373d0ab3b0f4b901c21f963e95db..eb0054aaf97b6ef489043bb97606f3f58ad8bedf 100644 --- a/packages/uni-h5-vite/src/plugins/manifestJson.ts +++ b/packages/uni-h5-vite/src/plugins/manifestJson.ts @@ -11,6 +11,7 @@ const defaultRouter = { mode: 'hash', base: '/', assets: 'assets', + routerBase: '/' } const defaultAsync = { @@ -44,9 +45,13 @@ export function uniManifestJsonPlugin(): Plugin { } if (!router.base) { router.base = '/' - } else { - router.base = new URL(router.base, 'http://localhost').pathname - } + } + + /** + * ssr时base和访问域名不一致导致跳到错误链接,其实应该区分server和client的部署路径,后续有需求可以加上 + */ + router.routerBase = new URL(router.base, 'http://localhost').pathname + const async = { ...defaultAsync, ...((h5 && h5.async) || {}) } const networkTimeout = normalizeNetworkTimeout(manifest.networkTimeout) diff --git a/packages/uni-h5/src/framework/plugin/router.ts b/packages/uni-h5/src/framework/plugin/router.ts index 9c15a35694bb712ede6953ddfeba6c051888bd34..145a4b1a0eb7beaf33d1d2c32d8db503a10c3ed1 100644 --- a/packages/uni-h5/src/framework/plugin/router.ts +++ b/packages/uni-h5/src/framework/plugin/router.ts @@ -45,17 +45,17 @@ function removeCurrentPages(delta: number = 1) { } function initHistory() { - let { base } = __uniConfig.router! - if (base === '/') { - base = '' + let { routerBase } = __uniConfig.router! + if (routerBase === '/') { + routerBase = '' } if (__NODE_JS__) { - return createMemoryHistory(base) + return createMemoryHistory(routerBase) } const history = __UNI_FEATURE_ROUTER_MODE__ === 'history' - ? createWebHistory(base) - : createWebHashHistory(base) + ? createWebHistory(routerBase) + : createWebHashHistory(routerBase) history.listen((_to, _from, info) => { if (info.direction === 'back') { removeCurrentPages(Math.abs(info.delta))