【发布时间】:2015-12-09 06:08:52
【问题描述】:
好的 - 我到底想念什么......花了一天半的时间试图解决这个问题,并且即将放弃 redux......
我有以下根路由...
...
import configureStore from 'NewApp/client/store';
import createBrowserHistory from 'history/lib/createBrowserHistory';
const history = createBrowserHistory();
const store = configureStore(history);
ReactDOM.render(
<Provider store={store}>
<Router
history={history}
children={routes}
{...clientOptions.props} />
</Provider>
, rootElement
);
...
我看到了 store 对象,但我一直收到错误消息说它不存在...
添加请求的附加代码:
...
import rootReducer from '../reducers';
const middlewares = [
thunkMiddleware,
loggerMiddleware,
];
const finalCreateStore = compose(
applyMiddleware(...middlewares),
window.devToolsExtension ? window.devToolsExtension() : f => f
)(createStore);
export default function configureStore(history, initialState) {
const store = finalCreateStore(rootReducer, initialState);
syncReduxAndRouter(history, store, state => state.router);
return store;
}
...
...
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { clearNotification } from '../actions/notifications';
import { logout } from '../actions/auth';
import App from '../components/App';
function mapStateToProps(state) {
return {
locale: state.app.locale,
loggingIn: state.auth.loggingIn,
messages: state.app.messages,
notification: state.notification,
title: state.app.title,
user: state.auth.user,
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({
clearNotification,
logout,
}, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(App);
【问题讨论】:
-
您是否从
react-redux导入了Provider? -
是的,我做到了...为了简洁起见,我只是将其他导入排除在外,否则我会遇到严重的失败 ;-)
-
你能显示你使用
connect的代码吗? -
我用连接和附加信息更新了问题
-
我从未见过
react-router以这种方式使用。您可以尝试将容器<App/>放在<Provider>内,看看它是否有效?
标签: reactjs reactjs-flux redux