diff --git a/src/runtime/getInitialProps.js b/src/runtime/getInitialProps.js index 30a57f9..476535e 100644 --- a/src/runtime/getInitialProps.js +++ b/src/runtime/getInitialProps.js @@ -23,6 +23,14 @@ export default options => Target => class extends Component { super(props, Target); } + componentWillMount() { + const { store } = this.props; + const { reducer } = options; + if (reducer) { + store.injectReducer(reducer); + } + } + async componentDidMount() { // 该方法在页面浏览器端渲染时会调用 // 在浏览器端动态添加reducer @@ -31,9 +39,6 @@ export default options => Target => class extends Component { if (!promise) { throw new Error('getInitialProps must pass in an object containing the key "promise"'); } - if (reducer) { - store.injectReducer(reducer); - } await promise({ store, match, query }); }