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:
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?
将case 'LOCATION_CHANGE'
更改为case '@@router/LOCATION_CHANGE'
。
Even better, use the constant provided by react-router
:
import { LOCATION_CHANGE } from 'connected-react-router';
// ...
switch (action.type) {
case LOCATION_CHANGE: {}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.