提交 c42f0dca 编写于 作者: 雪洛's avatar 雪洛

fix(ssr): router base error

上级 1de58dc2
......@@ -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)
......
......@@ -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))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册