2016-01-22 90 views
4

我一直在尝试设置react + react-router + redux + redux-simple-router没有成功。一切似乎工作正常,直到我添加redux-simple-router混合,之后我得到React + Redux简单路由器:找不到undefined

"[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()一个Express服务器反应模板。那是为什么它没有定义?我该怎么办?

注2:,如果我不是import BrowserHistory from 'react-router/lib/BrowserHistory'然后我得到

TypeError: history.listen is not a function;

+0

你试过'browserHistory'而不是'BrowserHistory'吗? – oobgam

+0

@路我从路由器导入'BrowserHistory' ..为什么'browserHistory'? –

+0

,因为'react-router'将它导出为'browserHistory',我认为它是区分大小写的https://github.com/rackt/react-router/blob/master/modules/index.js#L28 – oobgam

回答