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://www.f2er.com/react/303975.html