脚本宝典收集整理的这篇文章主要介绍了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
世界安静了
以上是脚本宝典为你收集整理的react-router4以后动态加载解决办法(code-split)全部内容,希望文章能够帮你解决react-router4以后动态加载解决办法(code-split)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。