Skip to content

Commit

Permalink
fix(router): 修复偶尔页面隐藏失败的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Littly committed Jun 21, 2019
1 parent 15bed06 commit b9f708a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/taro-router/src/router/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Taro from '@tarojs/taro-h5'
import Nerv from 'nervjs'
import Nerv, { nextTick } from 'nervjs'

import { tryToCall } from '../utils'
import { Location, RouteObj } from '../utils/types'
Expand Down Expand Up @@ -98,19 +98,21 @@ class Route extends Taro.Component<RouteProps, {}> {

this.matched = nextMatched

if (nextMatched) {
this.showPage()
if (!isRedirect) {
nextTick(() => {
if (nextMatched) {
this.showPage()
if (!isRedirect) {
scroller = scroller || getScroller()
scroller.set(this.scrollPos)
tryToCall(this.componentRef.componentDidShow, this.componentRef)
}
} else {
scroller = scroller || getScroller()
scroller.set(this.scrollPos)
tryToCall(this.componentRef.componentDidShow, this.componentRef)
this.scrollPos = scroller.get()
this.hidePage()
tryToCall(this.componentRef.componentDidHide, this.componentRef)
}
} else {
scroller = scroller || getScroller()
this.scrollPos = scroller.get()
this.hidePage()
tryToCall(this.componentRef.componentDidHide, this.componentRef)
}
})
}

shouldComponentUpdate () {
Expand All @@ -129,7 +131,7 @@ class Route extends Taro.Component<RouteProps, {}> {
hidePage () {
const dom = this.containerRef
if (!dom) {
return console.error(`showPage:fail Received a falsy component for route "${this.props.path}". Forget to export it?`)
return console.error(`hidePage:fail Received a falsy component for route "${this.props.path}". Forget to export it?`)
}
dom.style.display = 'none'
}
Expand Down

0 comments on commit b9f708a

Please sign in to comment.