diff --git a/src/core/service/plugins/app/router-guard.js b/src/core/service/plugins/app/router-guard.js index b3e478194959f956d0cf6389a708ae7cadb7cb69..98bca043c9c3ef7c3d5172345707e4ab35f6d61a 100644 --- a/src/core/service/plugins/app/router-guard.js +++ b/src/core/service/plugins/app/router-guard.js @@ -167,12 +167,22 @@ function afterEach (to, from) { const fromVm = currentPages.find(pageVm => pageVm.$page.id === fromId) // 使用 beforeEach 时的 pages + function unloadPage (vm) { + if (vm) { + callPageHook(vm, 'onUnload') + const index = currentPages.indexOf(vm) + if (index >= 0) { + currentPages.splice(index, 1) + } + } + } + switch (to.type) { case 'navigateTo': // 前一个页面触发 onHide fromVm && callPageHook(fromVm, 'onHide') break case 'redirectTo': // 前一个页面触发 onUnload - fromVm && callPageHook(fromVm, 'onUnload') + unloadPage(fromVm) break case 'switchTab': if (from.meta.isTabBar) { // 前一个页面是 tabBar 触发 onHide,非 tabBar 页面在 beforeEach 中已触发 onUnload @@ -183,11 +193,11 @@ function afterEach (to, from) { break default: if (fromId && fromId > toId) { // history back - fromVm && callPageHook(fromVm, 'onUnload') + unloadPage(fromVm) if (this.$router._$delta > 1) { deltaIds.reverse().forEach(deltaId => { const pageVm = currentPages.find(pageVm => pageVm.$page.id === deltaId) - pageVm && callPageHook(pageVm, 'onUnload') + unloadPage(pageVm) }) } }