Tylerlee12 Tylerlee12 - 1 month ago 24
React JSX Question

How do I listen for react-router location change in redux reducer?

I have a React Redux app, and am trying to listen for a

react-router
location change in one of my reducers. I am using
hashHistory
, not
browserHistory
. In my Redux devtools, I can see it is firing an action when the location changes:

enter image description here

However, in my reducer, when I listen for 'LOCATION_CHANGE', it doesn't catch anything.

import * as types from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';

export default function listingsReducer(state = initialState.listings, action) {
switch (action.type) {
case 'LOCATION_CHANGE': {
console.log(action); //currently doesn't get into this case block
return state;
}
default:
return state;
}
}


What do I have to use in order to handle this action in my reducer?

Answer

Change case 'LOCATION_CHANGE' to case '@@router/LOCATION_CHANGE'.