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...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值