gilbarbara/simple-react-router-redux

View on GitHub
src/reducer.js

Summary

Maintainability
A
0 mins
Test Coverage
import { LOCATION_CHANGE } from './actions';

export default history => {
  const initialRouterState = {
    location: history.location,
    action: history.action,
  };

  /*
   * This reducer will update the state with the most recent location history
   * has transitioned to.
   */
  return (state = initialRouterState, { type, payload } = {}) => {
    if (type === LOCATION_CHANGE) {
      return {
        ...state,
        ...payload,
      };
    }

    return state;
  };
};