【问题标题】:react-router-redux history not being accepted (from sample code)react-router-redux 历史不被接受(来自示例代码)
【发布时间】:2017-11-14 00:19:44
【问题描述】:

使用 README 中的示例

https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux

我在我的索引中创建了这个布局:

// attach the redux dev tools extension for Chrome
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

// apply router logic as middleware
const history = createHistory();
const router_mw = routerMiddleware(history);


// second arg to createStore is the inital redux store state
const store = createStore(
  reducers,
  initialState,
  composeEnhancers(
    applyMiddleware(
      ReduxPromise,
      ReduxThunk,
      router_mw
    )
));

// --> add routes for logs, opsec, etc. later
ReactDOM.render(
  <Provider store={ store }>
    <ConnectedRouter history={ history }>  // <- error here
      <div>
        <Route exact path="/" component={ LoginScreen } />
        <Route path="/comp1" component={ comp1 } />
        <Route path="/comp2" component={ comp2 } />
      </div>
    </ConnectedRouter>
  </Provider>
  , document.getElementById('root')
);

任何编译它的尝试都会在 ConnectedRouter 入口点抱怨 { history }:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check your code at index.js:52.

我错过了什么?这是 react-router-redux 改造 - 回到 react-router(并将 ConnectedRouter 更改为 BrowserRouter),一切都按预期工作。

【问题讨论】:

    标签: react-router react-router-redux


    【解决方案1】:

    我使用react-router-dom@4.2.2 并遇到同样的问题,直到将react-router-redux 更新为^5.0.0-alpha.9

    如果你使用react-router-dom@4,你应该使用react-router-redux@5,在react-router-redux repo中说:

    react-router-redux 的下一个版本将是 5.0.0,并将与 react-router 4.x 兼容。它目前正在积极开发over there。随时提供帮助!

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 2018-04-02
      • 2018-05-14
      • 2021-10-24
      • 1970-01-01
      • 2018-12-09
      • 2018-10-15
      • 2018-08-07
      • 2017-07-07
      相关资源
      最近更新 更多