react-router-redux:无法在syncHistoryWithStore读取未定义的属性'listen'

时间:2017-03-02 09:54:07

标签: react-router-redux

我正在将Redact Ract应用程序重构为Redux。 我已经确定了一些测试过的动作和减速器。 我在Router&历史。
我收到了错误:

  

未捕获的TypeError:无法在syncHistoryWithStore上读取未定义的属性'listen'

来自简单的代码:

//configureStore.jsx
import redux from 'redux';
import {buildingReducer, levelReducer, roomReducer} from 'reducers';
import {routerReducer} from 'react-router-redux';

export let configure = (initialState = {}) => {
    let reducer = redux.combineReducers({
        building: buildingReducer,
        level: levelReducer,
        room: roomReducer,
        routing: routerReducer
   });

   let store = redux.createStore(reducer, initialState, redux.compose(
    window.devToolsExtension ? window.devToolsExtension() : f => f));

   return store;

};

&安培;

//app.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute, browserHistory, hashHistory } from 'react-router';
import {Provider} from 'react-redux';
import {syncHistoryWithStore} from 'react-router-redux'

var actions = require('actions');
var store = require('configureStore').configure();

const history = syncHistoryWithStore(browserHistory, store);

ReactDOM.render(
  <Provider store={store}>
    <Router history={history}>
        <Route path="/" component={Main}>
            <IndexRoute component={Map}/>
            <Route path="report" component={Report}/>
            <Route path="about" component={About}/>
        </Route>
    </Router>
  </Provider>,
 document.getElementById('react_app')
);

我不知道为什么会这样:(

4 个答案:

答案 0 :(得分:16)

我按照comment解决了这个问题。这是在我更新到&#34; react-router&#34;:&#34; ^ 4.1.1&#34;和&#34; react-router-redux&#34;:&#34; ^ 4.0.8&#34;。这确实解决了使用来自react-router的browserHistory的问题,但是可以解决这个问题。

解决方法需要您:

order by substring_index(myid, '-', 1) + 0, substring_index(myid, '-', -1) + 0 

关于这个问题的评论似乎建议尝试2个插头的不同组合。我通过安装&#34; react-router&#34;:&#34; ^ 3.0.2&#34;来测试代码。和&#34; react-router-redux&#34;:&#34; ^ 4.0.8&#34;这也有效。

答案 1 :(得分:4)

我正在使用react_on_rails项目。我通过降级到以下版本来解决问题。

"react-redux": "^4.4.6",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.7",

答案 2 :(得分:2)

我没有看到您编码的问题。它适用于我这个组合: “react-router”:“^ 3.0.2”,“react-router-redux”:“^ 4.0.8”

问题的一个可能来源是您使用的是known to have issues的其他版本。

答案 3 :(得分:0)

如果有人在寻找最新的解决方案:

看起来他们已经更新了历史回购: -

使用'createHistory'代替'createBrowserHistory'

请在商店中尝试以下内容:

import { createHistory } from 'history';
const history = syncHistoryWithStore(createHistory(), store);

并确保'routerReducer'作为一个额外的缩减器添加到您的合并缩减器中。

问候。