connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

Add previous location to the action

Open aczekajski opened this issue 5 years ago • 1 comments

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).

aczekajski avatar Apr 21 '20 16:04 aczekajski

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.

vdyalex avatar Aug 17 '20 16:08 vdyalex