我一直在尝试设置react
++ ,react-router
但没有成功。一切似乎都很好,直到我添加到混合物中,之后我得到redux
redux-simple-router
redux-simple-router
"[TypeError: Cannot read property 'listen' of undefined]
即使我传入 BrowserHistory 对象。
这是代码 -
import React from 'react'
import ReactDOM from 'react-dom'
import { Route, Router, BrowserHistory } from 'react-router';
import HashHistory from 'react-router/lib/HashHistory';
import { compose, combineReducers, applyMiddleware, createStore } from 'redux'
import { Provider } from 'react-redux'
import { syncHistory, routeReducer } from 'redux-simple-router'
import * as reducers from 'reducers/reducers'
import Blank from 'routes/blank';
export default (withHistory, onUpdate) => {
const reducer = combineReducers(Object.assign({}, reducers, {
routing: routeReducer
}));
const reduxRouterMiddleware = syncHistory(BrowserHistory)
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore)
const store = createStoreWithMiddleware(reducer)
return (
<Provider store={store}>
<Router history={BrowserHistory} onUpdate={onUpdate}>
<Route path='/' component={Blank} />
</Router>
</Provider>
);
};
注意:我刚刚发现我正在使用renderToString()
. 这就是为什么它没有定义?我该怎么办?
注2:如果我改为import BrowserHistory from 'react-router/lib/BrowserHistory'
,我会得到
TypeError: history.listen is not a function
;