首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react路由器-redux历史记录不被接受(来自示例代码)

react路由器-redux历史记录不被接受(来自示例代码)
EN

Stack Overflow用户
提问于 2017-06-12 13:37:08
回答 1查看 114关注 0票数 1

使用自述文件中的示例

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

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

代码语言:javascript
复制
// 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 }:

代码语言:javascript
复制
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),一切都如预期的那样工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-14 15:05:22

我使用了react-router-dom@4.2.2,在将react-router-redux更新为^5.0.0-alpha.9之前也遇到了同样的问题。

如果您正在使用react-router-dom@4,您应该使用react-router-redux@5,这在反应-路由器-redux回购中是这样说的

下一个版本的and路由器-redux将是5.0.0,并将兼容反应路由器4.x.目前正在积极开发在那边。随时可以帮忙!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44500858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档