react-router4今后动态加载解决办法(code-split)

react-router都升级到5.0了,之前用的2.*,想用create-react-app新建个项目用一下

首先是react-router-redux用法变了,使用了ConnectedRouter,本认为毛病在这里,折腾半天发明不是,

ReactDOM.render(
    <Provider store={store}>
        <ConnectedRouter history={history}>
           <App/>
        </ConnectedRouter>
    </Provider>,
    document.getElementById('root')
) 

第二官方的code-split计划https://reacttraining.cn/web/…

看文档,不多说,然则,一定会碰到以下报错

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: null. Check your code at index.js:44.
    in Bundle (at index.js:43)
    in Abouts (created by Route)
    in Route (at index.js:56)
    in div (at index.js:54)
    in App (at index.js:67)
    in Router (created by ConnectedRouter)
    in ConnectedRouter (at index.js:66)
    in Provider (at index.js:65)

google了半天,
bundle.js里,render要领里,改写

render() {
    return this.props.children(this.state.mod)
  }

为:

return this.state.mod ? this.props.children(this.state.mod) : null

天下平静了

github地点:https://github.com/jiangbo201…

    原文作者:紫气东来_姜波
    原文地址: https://segmentfault.com/a/1190000009461996
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞