From b27aac4d355a35f98f9ee4583860b8ac4af90817 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 21 May 2019 18:05:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E5=A4=96=E9=83=A8=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20history=20=E5=AF=BC=E8=87=B4=E8=B7=AF=E7=94=B1=E5=8D=A1?= =?UTF-8?q?=E5=9C=A8=E5=BD=93=E5=89=8D=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/service/plugins/app/router-guard.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/service/plugins/app/router-guard.js b/src/core/service/plugins/app/router-guard.js index 9eb422360..dc281997e 100644 --- a/src/core/service/plugins/app/router-guard.js +++ b/src/core/service/plugins/app/router-guard.js @@ -58,8 +58,8 @@ function reLaunch (toName) { // 重新reLaunch至首页可能会被keepAlive,先手动强制destroy pages[i].$destroy() } - this.keepAliveInclude = [] - // 清空 positionStore + this.keepAliveInclude = [] + // 清空 positionStore positionStore = Object.create(null) } @@ -69,8 +69,15 @@ function beforeEach (to, from, next, routes) { currentPages = getCurrentPages(true) // 每次 beforeEach 时获取当前currentPages,因为 afterEach 之后,获取不到上一个 page 了,导致无法调用 onUnload const fromId = from.params.__id__ const toId = to.params.__id__ + const toName = to.meta.name + '-' + toId 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跳转 next({ path: to.path, @@ -78,7 +85,6 @@ function beforeEach (to, from, next, routes) { }) } else { const fromName = from.meta.name + '-' + fromId - const toName = to.meta.name + '-' + toId switch (to.type) { case 'navigateTo': @@ -181,4 +187,4 @@ export default function initRouterGuard (appVm, routes) { appVm.$router.afterEach(function (to, from) { afterEach.call(appVm, to, from) }) -} +} -- GitLab