diff --git a/packages/taro-router/src/router/page.ts b/packages/taro-router/src/router/page.ts index b7025fa64f58..c0e17000a9f3 100644 --- a/packages/taro-router/src/router/page.ts +++ b/packages/taro-router/src/router/page.ts @@ -218,6 +218,8 @@ export default class PageHandler { pageEl.style.zIndex = '1' } + eventCenter.trigger('__taroPageWillShowAfterDestroyed') + this.unloadTimer = setTimeout(() => { this.unloadTimer = null this.lastUnloadPage?.onUnload?.() @@ -235,6 +237,14 @@ export default class PageHandler { if (delta >= 1) this.unload(stacks.last, delta) } + willShow (page?: PageInstance | null) { + if (!page) return + const pageEl = this.getPageContainer(page) + if (pageEl) { + pageEl.classList.remove('taro_page_shade') + } + } + show (page?: PageInstance | null, pageConfig: Route = {}, pageNo = 0) { if (!page) return diff --git a/packages/taro-router/src/router/spa.ts b/packages/taro-router/src/router/spa.ts index d1f3126369d0..12848208ac32 100644 --- a/packages/taro-router/src/router/spa.ts +++ b/packages/taro-router/src/router/spa.ts @@ -155,6 +155,12 @@ export function createRouter ( const delta = stacks.getDelta(pathname) // NOTE: Safari 内核浏览器在非应用页面返回上一页时,会触发额外的 POP 事件,此处需避免当前页面被错误卸载 if (currentPage !== stacks.getItem(prevIndex)) { + eventCenter.once('__taroPageWillShowAfterDestroyed', () => { + if (prevIndex > -1) { + const pageInstance = stacks.getItem(prevIndex) + pageInstance && handler.willShow(pageInstance) + } + }) handler.unload(currentPage, delta, prevIndex > -1) if (prevIndex > -1) { eventCenter.once('__taroPageOnShowAfterDestroyed', () => { diff --git a/packages/taro-router/src/style.ts b/packages/taro-router/src/style.ts index 7a025b4e2b3f..ab3a3405e27f 100644 --- a/packages/taro-router/src/style.ts +++ b/packages/taro-router/src/style.ts @@ -21,6 +21,7 @@ body { .taro_router > .taro_page.taro_tabbar_page, .taro_router > .taro_page.taro_page_show.taro_page_stationed { transform: none; + transition: none; } .taro_router > .taro_page.taro_page_show {