提交 e8f55847 编写于 作者: Q qiang

fix: unload

上级 85e7a02f
......@@ -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)
})
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册