【发布时间】:2017-02-18 01:08:23
【问题描述】:
我正在尝试使用 express.js 服务器为我的 react-redux 应用程序实现通用渲染,我正在关注以下教程:http://redux.js.org/docs/recipes/ServerRendering.html
每当我尝试按照教程中所述将 rootreducer 或 App 文件导入 express server.js 文件时,我都会收到以下错误:
\node_modules\react-router-redux\lib\sync.js:105
unsubscribeFromHistory = history.listen(handleLocationChange);
^
TypeError: Cannot read property 'listen' of undefined
at syncHistoryWithStore (C:\Users\user pc\Desktop\citydrill\node_modules\react-router-redux\lib\sync.js:105:35)
这是我的商店文件相关代码:
import { syncHistoryWithStore } from 'react-router-redux';
import { browserHistory } from 'react-router';
const store = createStore(rootReducer, initialState, compose(
applyMiddleware(thunk)
));
export const history = syncHistoryWithStore(browserHistory, store);
然后我只是像这样在 clientApp 中使用历史常量:
const router = (
<Provider store={store}>
<Router history={history}>
<Route name="Home" path="/" component={App}>
<IndexRoute name="Home" component={Landing}></IndexRoute>
</Route>
</Router>
</Provider>
)
除了 redux.js.org 中的教程之外,我也尝试了许多不同的教程,但我总是卡在这一点上,因为我总是必须从我的 express server.js 文件中的客户端代码中导入一些文件,并且无论何时我这样做我总是得到同样的错误。
如何实现通用 redux?我究竟做错了什么?我遵循了这么多教程,但没有一个提到这个错误,为什么它对这些人有用,但在我的应用程序中却没有?
感谢您的帮助
【问题讨论】:
标签: javascript node.js reactjs redux react-router-redux