更新资料
感谢@Dominic Tobias和@gabdallah发现了我的尴尬错误。
正确的答案当然是正确的。
因此,请尝试检查action.payload。
action.payload
关于switch语句和action对象的其他注释,我们指的是我在示例中所做的错误,此后我已对其进行了纠正。
想象一下,我将以下两个减速器结合了起来;
import { combineReducers } from 'redux' import { routerStateReducer } from 'redux-router' import entries from './entries' export default combineReducers({ router: routerStateReducer, entries })
在这种情况下,我想基于全局状态的另一部分来改变条目状态。redux-router提供的路由器状态,例如以实现分页。
我该怎么做?
// entries.js import { ROUTER_DID_CHANGE } from 'redux-router/lib/constants' const initialState = {} function entries (state = initialState, action) { switch (action.type) { case ROUTER_DID_CHANGE: // How can I access `state.router` here in order to do something like this; if (routerState.location.pathname === '/entries') { return { ...state, page: routerState.location.query.page || state.page, limit: routerState.location.query.limit || state.limit } } return state } }
我想到了其他一些方法;
Entries
fetchData
其他有用的信息;
所讨论的实现是Universal App在很大程度上受react-redux-universal-hot-example的启发
相关部门
我怎样才能达到这种或类似的行为?我什至在想这是正确的方法吗?
早在对开发人员来说事情变得更简单之前,人们会听取历史对象上的popstate事件;)
看起来所需的信息正在执行中?
history.listen((error, nextRouterState) => { ... store.dispatch(routerDidChange(nextRouterState));
和动作:
export function routerDidChange(state) { return { type: ROUTER_DID_CHANGE, payload: state }; }
但是,您的switch语句正在使用action而不是,action.type所以这里有些混乱。.您也不需要执行action = {}任何操作- 请参阅http://redux.js.org/docs/basics/Reducers.html
action
action.type
action = {}