react-router4之後動態加載解決辦法(code-split)

react-router都升級到5.0了,以前用的2.*,想用create-react-app新建個項目用一下react

首先是react-router-redux用法變了,使用了ConnectedRouter,本覺得錯誤在這裏,折騰半天發現不是,git

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

第二官方的code-split方案https://reacttraining.cn/web/...github

看文檔,很少說,可是,必定會遇到以下報錯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方法裏,改寫redux

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

爲:react-router

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

世界安靜了app

github地址:https://github.com/jiangbo201...ide

相關文章
相關標籤/搜索