提交 e8f55847 编写于 作者: Q qiang

fix: unload

上级 85e7a02f
...@@ -167,12 +167,22 @@ function afterEach (to, from) { ...@@ -167,12 +167,22 @@ function afterEach (to, from) {
const fromVm = currentPages.find(pageVm => pageVm.$page.id === fromId) // 使用 beforeEach 时的 pages 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) { switch (to.type) {
case 'navigateTo': // 前一个页面触发 onHide case 'navigateTo': // 前一个页面触发 onHide
fromVm && callPageHook(fromVm, 'onHide') fromVm && callPageHook(fromVm, 'onHide')
break break
case 'redirectTo': // 前一个页面触发 onUnload case 'redirectTo': // 前一个页面触发 onUnload
fromVm && callPageHook(fromVm, 'onUnload') unloadPage(fromVm)
break break
case 'switchTab': case 'switchTab':
if (from.meta.isTabBar) { // 前一个页面是 tabBar 触发 onHide,非 tabBar 页面在 beforeEach 中已触发 onUnload if (from.meta.isTabBar) { // 前一个页面是 tabBar 触发 onHide,非 tabBar 页面在 beforeEach 中已触发 onUnload
...@@ -183,11 +193,11 @@ function afterEach (to, from) { ...@@ -183,11 +193,11 @@ function afterEach (to, from) {
break break
default: default:
if (fromId && fromId > toId) { // history back if (fromId && fromId > toId) { // history back
fromVm && callPageHook(fromVm, 'onUnload') unloadPage(fromVm)
if (this.$router._$delta > 1) { if (this.$router._$delta > 1) {
deltaIds.reverse().forEach(deltaId => { deltaIds.reverse().forEach(deltaId => {
const pageVm = currentPages.find(pageVm => pageVm.$page.id === deltaId) const pageVm = currentPages.find(pageVm => pageVm.$page.id === deltaId)
pageVm && callPageHook(pageVm, 'onUnload') unloadPage(pageVm)
}) })
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册