提交 b27aac4d 编写于 作者: Q qiang

fix: 解决某些情况下外部修改 history 导致路由卡在当前页面的问题

上级 f32265a0
...@@ -58,8 +58,8 @@ function reLaunch (toName) { ...@@ -58,8 +58,8 @@ function reLaunch (toName) {
// 重新reLaunch至首页可能会被keepAlive,先手动强制destroy // 重新reLaunch至首页可能会被keepAlive,先手动强制destroy
pages[i].$destroy() pages[i].$destroy()
} }
this.keepAliveInclude = [] this.keepAliveInclude = []
// 清空 positionStore // 清空 positionStore
positionStore = Object.create(null) positionStore = Object.create(null)
} }
...@@ -69,8 +69,15 @@ function beforeEach (to, from, next, routes) { ...@@ -69,8 +69,15 @@ function beforeEach (to, from, next, routes) {
currentPages = getCurrentPages(true) // 每次 beforeEach 时获取当前currentPages,因为 afterEach 之后,获取不到上一个 page 了,导致无法调用 onUnload currentPages = getCurrentPages(true) // 每次 beforeEach 时获取当前currentPages,因为 afterEach 之后,获取不到上一个 page 了,导致无法调用 onUnload
const fromId = from.params.__id__ const fromId = from.params.__id__
const toId = to.params.__id__ const toId = to.params.__id__
const toName = to.meta.name + '-' + toId
if (toId === fromId) { // 相同页面阻止 if (toId === fromId) { // 相同页面阻止
next(false) // 处理外部修改 history 导致卡在当前页面的问题
if (to.fullPath !== from.fullPath) {
removeKeepAliveInclude.call(this, toName)
next()
} else {
next(false)
}
} else if (to.meta.id && to.meta.id !== toId) { // id 不妥,replace跳转 } else if (to.meta.id && to.meta.id !== toId) { // id 不妥,replace跳转
next({ next({
path: to.path, path: to.path,
...@@ -78,7 +85,6 @@ function beforeEach (to, from, next, routes) { ...@@ -78,7 +85,6 @@ function beforeEach (to, from, next, routes) {
}) })
} else { } else {
const fromName = from.meta.name + '-' + fromId const fromName = from.meta.name + '-' + fromId
const toName = to.meta.name + '-' + toId
switch (to.type) { switch (to.type) {
case 'navigateTo': case 'navigateTo':
...@@ -181,4 +187,4 @@ export default function initRouterGuard (appVm, routes) { ...@@ -181,4 +187,4 @@ export default function initRouterGuard (appVm, routes) {
appVm.$router.afterEach(function (to, from) { appVm.$router.afterEach(function (to, from) {
afterEach.call(appVm, to, from) afterEach.call(appVm, to, from)
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册