Redux; accessing other parts of the state when using composed reducers via combineReducers

前端 未结 1 533
生来不讨喜
生来不讨喜 2021-02-13 05:03

Update

Thanks to @Dominic Tobias and @gabdallah for spotting my embarrassing mistake.

The correct answer is of course;

so

相关标签:
1条回答
  • 2021-02-13 05:43

    Back in the old days before things got simpler for a developer people would listen to the popstate event on the history object ;)

    It looks like the required info is on the action?

    history.listen((error, nextRouterState) => {
     ...
     store.dispatch(routerDidChange(nextRouterState));
    

    and the action:

    export function routerDidChange(state) {
      return {
        type: ROUTER_DID_CHANGE,
        payload: state
      };
    }
    

    So try checking action.payload.

    However your switch statement is using action instead of action.type so there's something fishy going on there.. You shouldn't need to do action = {} either - see http://redux.js.org/docs/basics/Reducers.html

    0 讨论(0)
提交回复
热议问题