mys*_*iar 7 react-router-redux
我正在将Redact Ract应用程序重构为Redux.我已经确定了一些测试的动作和减速器.我在路由器和历史上得到了堆栈.
我收到错误:
未捕获的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;
};
Run Code Online (Sandbox Code Playgroud)
&
//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')
);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会发生这种情况:(
小智 16
我按照这个评论解决了这个问题.在我更新为"react-router"之后:"^ 4.1.1"和"react-router-redux":"^ 4.0.8".这确实解决了使用来自react-router的browserHistory的问题,但是给你一个解决方法.
解决方法需要您:
import { createBrowserHistory } from 'history';
const history = syncHistoryWithStore(createBrowserHistory(), store);
Run Code Online (Sandbox Code Playgroud)
关于这个问题的评论似乎建议尝试2个插头的不同组合.我通过安装"react-router"测试代码:"^ 3.0.2"和"react-router-redux":"^ 4.0.8",这也有效.
| 归档时间: |
|
| 查看次数: |
7307 次 |
| 最近记录: |