Javascript 反应+;Redux简单路由器:找不到未定义的侦听
我一直在尝试设置Javascript 反应+;Redux简单路由器:找不到未定义的侦听,javascript,reactjs,redux,react-router-redux,Javascript,Reactjs,Redux,React Router Redux,我一直在尝试设置react+react路由器+redux+redux简单路由器,但没有成功。在我将redux simple router添加到混音中之前,一切似乎都很好,然后我就可以 “[类型错误:无法读取未定义的属性'listen'”即使我正在传递BrowserHistory对象 这是密码- import React from 'react' import ReactDOM from 'react-dom' import { Route, Router, BrowserHistory } fr
react
+react路由器
+redux
+redux简单路由器
,但没有成功。在我将redux simple router
添加到混音中之前,一切似乎都很好,然后我就可以
“[类型错误:无法读取未定义的属性'listen'”
即使我正在传递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>
);
};
从“React”导入React
从“react dom”导入react dom
从“react Router”导入{Route,Router,BrowserHistory};
从“react router/lib/HashHistory”导入HashHistory;
从“redux”导入{compose,combinereducer,applyMiddleware,createStore}
从“react redux”导入{Provider}
从“redux简单路由器”导入{syncHistory,routeReducer}
从“减速器/减速器”导入*作为减速器
从“路线/空白”导入空白;
导出默认值(带历史记录,onUpdate)=>{
const reducer=combinereducer(Object.assign({},reducer{
路由:路由传感器
}));
const reduxRouterMiddleware=syncHistory(浏览器历史记录)
const createStoreWithMiddleware=applyMiddleware(reduxRouterMiddleware)(createStore)
const store=createStoreWithMiddleware(reducer)
返回(
);
};
注意:我刚刚发现我正在使用renderToString()
在express server中编译react模板。这就是为什么它没有定义的原因吗?我该怎么做
注2:如果我从“react router/lib/BrowserHistory”导入浏览器历史记录,则我得到
TypeError:history.listen不是一个函数
;我刚才也有同样的错误。我是根据这里的教程得到的:
然后我意识到上面有这样一条信息:
注意:此示例使用react router的2.0 API,该API当前为
在版本2.0.0-rc5下发布
我的包裹是这样的:
history ^1.17.0 → ^2.0.0-rc2
react-router ^1.0.3 → ^2.0.0-rc5
…解决了错误。您是否尝试了
browserHistory
而不是browserHistory
?@Road我正在从路由器导入browserHistory
。为什么browserHistory
?因为react-router
将其导出为browserHistory
,我认为它区分大小写@Road我尝试过它,相同的t欣..见注#2我补充..您是在做服务器端还是客户端?