Skip to content

Commit

Permalink
fix: csr getinitialProps
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuang committed Apr 13, 2020
1 parent ecb81c2 commit cb88ed7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 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.5",
"version": "3.6.6",
"description": "utils for ykfe",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
6 changes: 4 additions & 2 deletions packages/ykfe-utils/src/components/getinitialProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ function GetInitialProps (WrappedComponent: FC): React.ComponentClass {
}

async componentDidMount () {
// history push的时候需要调用getInitialProps
if (this.props.history && this.props.history.action === 'PUSH') {
console.log('xx')
// csr 或者 history push的时候需要调用getInitialProps
if ((this.props.history && this.props.history.action !== 'POP' || !window.__USE_SSR__)) {
await this.getInitialProps()
}
}

async getInitialProps () {
console.log('hoc get')
// csr首次进入页面以及csr/ssr切换路由时才调用getInitialProps
const props = this.props
if (WrappedComponent.preload) {
Expand Down

0 comments on commit cb88ed7

Please sign in to comment.