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

fix(ssr): router base error

上级 1de58dc2
...@@ -11,6 +11,7 @@ const defaultRouter = { ...@@ -11,6 +11,7 @@ const defaultRouter = {
mode: 'hash', mode: 'hash',
base: '/', base: '/',
assets: 'assets', assets: 'assets',
routerBase: '/'
} }
const defaultAsync = { const defaultAsync = {
...@@ -44,9 +45,13 @@ export function uniManifestJsonPlugin(): Plugin { ...@@ -44,9 +45,13 @@ export function uniManifestJsonPlugin(): Plugin {
} }
if (!router.base) { if (!router.base) {
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 async = { ...defaultAsync, ...((h5 && h5.async) || {}) }
const networkTimeout = normalizeNetworkTimeout(manifest.networkTimeout) const networkTimeout = normalizeNetworkTimeout(manifest.networkTimeout)
......
...@@ -45,17 +45,17 @@ function removeCurrentPages(delta: number = 1) { ...@@ -45,17 +45,17 @@ function removeCurrentPages(delta: number = 1) {
} }
function initHistory() { function initHistory() {
let { base } = __uniConfig.router! let { routerBase } = __uniConfig.router!
if (base === '/') { if (routerBase === '/') {
base = '' routerBase = ''
} }
if (__NODE_JS__) { if (__NODE_JS__) {
return createMemoryHistory(base) return createMemoryHistory(routerBase)
} }
const history = const history =
__UNI_FEATURE_ROUTER_MODE__ === 'history' __UNI_FEATURE_ROUTER_MODE__ === 'history'
? createWebHistory(base) ? createWebHistory(routerBase)
: createWebHashHistory(base) : createWebHashHistory(routerBase)
history.listen((_to, _from, info) => { history.listen((_to, _from, info) => {
if (info.direction === 'back') { if (info.direction === 'back') {
removeCurrentPages(Math.abs(info.delta)) removeCurrentPages(Math.abs(info.delta))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册