connected-react-router
connected-react-router copied to clipboard
Add previous location to the action
It would be nice to have a prevLocation also available in LOCATION_CHANGE action. Now if you want to save the previous location in store, you also have to save a current location too, like this:
case LOCATION_CHANGE: {
return {
previous: state.current,
current: action.payload.location,
};
}
Current location shouldn't be stored there (because the only source of truth about location should be a router itself, not something stored in redux store).
I've been struggling to check the previous location before filtering an action. It would be much better for reacting to history changes. This should be the proper way: observing the changes in a single place. I don't want to play with redux-saga adding multiple effects just to check what was the previous location.
I agree that this should be the proper way to just inform the redux about a history change.
@aczekajski I wouldn't say that the redux is even a source of truth about the location, but it's rather for reacting to history changes and triggering redux actions. The "current location" would rather be a piece of information. It's added to the redux store because of the time-traveling feature.