Skip to content

Commit

Permalink
fix: 修复history action判断
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Apr 1, 2020
1 parent 3217090 commit c2ff736
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/ykfe-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ykfe-utils",
"version": "3.6.0",
"version": "3.6.1",
"description": "utils for ykfe",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/ykfe-utils/src/components/getinitialProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react'
import { withRouter, RouteComponentProps } from 'react-router-dom'
import { FC } from '../interface/fc'

let getProps = false
let routerChanged = false
interface IState {
extraProps: Object
}
Expand All @@ -14,15 +14,15 @@ function GetInitialProps (WrappedComponent: FC): React.ComponentClass {
this.state = {
extraProps: {}
}
if (!getProps) {
if (!routerChanged) {
// csr渲染模式下无论是首次打开页面还是路由跳转都需要客户端需要调用getInitialProps
// 进行过history push或者reaplace操作之后,每次进行单页跳转客户端都需要调用getInitialProps
getProps = !window.__USE_SSR__ || props.history && props.history.action === ('PUSH' || 'REPLACE')
routerChanged = !window.__USE_SSR__ || props.history && /push|replace/i.test(props.history.action)
}
}

async componentDidMount () {
if (getProps) {
if (routerChanged) {
await this.getInitialProps()
}
}
Expand Down

0 comments on commit c2ff736

Please sign in to comment.