加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 07:20:04 所属栏目:百科 来源:网络整理
导读:react-router都升级到5.0了,之前用的2.*,想用create-react-app新建个项目用一下 首先是react-router-redux用法变了,使用了ConnectedRouter,本以为错误在这里,折腾半天发现不是, ReactDOM.render( Provider store={store} ConnectedRouter history={his

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读