For React Router 5 and Redux, you can listen to location changes and save the last path in the store.
Define an action and gear for your state branch, e.g. misc :
// Partial state const miscState = { prevPath: '', // ...other properties } // Action creator export const updatePrevPathAction = path => ({ type: 'misc/prev-path', payload: path, }) // Partial reducer export const miscReducer = (state = miscState, action) { switch (action.type) { case 'misc/prev-path': if (state.prevPath === action.payload) { state = { ...state, prevPath: action.payload } } break // ...handle other actions } return state }
Then, when creating the store, if you use a custom browser history:
// Import the history import { browserHistory } from 'your-singleton-loc/browser-history' import { updatePrevPathAction, miscReducer } from './misc-state' // ... // Create the store const store = configureStore(...) // Create a listener for browser history const pathListener = loc => { store.dispatch(updatePrevPathAction(loc.pathname)) } // Register the listener browserHistory.listen(pathLisneter) // Save the current uri pathListener(browserHistory.location) // done return store
If you are not using a custom browser history, you can do the same in the App.jsx file using the router's history property.
This solution is for the entire application and does not require response-router-redux.
source share