Commit 7c637408 by fukai

支持新钩子

parent f75165df
......@@ -83,6 +83,7 @@ class LiveRoute extends React.Component<PropsType, any> {
public previousDisplayStyle: string | null = null
public liveState: LiveState = LiveState.NORMAL_RENDER_ON_INIT
public currentSideEffect: SideEffect[] = [SideEffect.NO_SIDE_EFFECT]
public wrapperedRef:any = null
public componentDidMount() {
this.getRouteDom()
......@@ -105,10 +106,16 @@ class LiveRoute extends React.Component<PropsType, any> {
this.clearScroll()
}
public passRef = (ref) =>
{
this.wrapperedRef = ref
}
// get DOM of Route
public getRouteDom = () => {
public getRouteDom = (ref?:any) => {
let routeDom = ReactDOM.findDOMNode(this)
this.routeDom = (routeDom as CacheDom) || this.routeDom
ref && this.passRef(ref)
}
public hideRoute() {
......@@ -256,7 +263,7 @@ class LiveRoute extends React.Component<PropsType, any> {
staticContext
// from withRouter, same as RouterContext.Consumer ⬆️
} = this.props
const hook = this[hookName]
const hook = this.props[hookName]
const context = { history, location, match, staticContext }
const matchOfPath = this.props.path ? matchPath(location.pathname, this.props) : context.match
const matchOfLivePath = this.isLivePathMatch(livePath, alwaysLive, location!.pathname, {
......@@ -266,6 +273,15 @@ class LiveRoute extends React.Component<PropsType, any> {
sensitive
})
const matchAnyway = matchOfPath || matchOfLivePath
if(hookName == 'onHide')
{
this.wrapperedRef && this.wrapperedRef.componentOnHide && this.wrapperedRef.componentOnHide(location!, matchAnyway, history, livePath, alwaysLive)
}else if(hookName == 'onReappear')
{
this.wrapperedRef && this.wrapperedRef.componentOnReappear && this.wrapperedRef.componentOnReappear(location!, matchAnyway, history, livePath, alwaysLive)
}
if (typeof hook === 'function') {
hook(location!, matchAnyway, history, livePath, alwaysLive)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment