Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit eb9e799

Browse files
committed
Restore location after devtools reset
1 parent 8780e56 commit eb9e799

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: src/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ function syncReduxAndRouter(history, store) {
4242
);
4343
}
4444

45+
// Capture the initial path so that redux devtools knows where
46+
// to go back after a 'RESET' action
47+
let initialPath;
48+
4549
history.listen(location => {
50+
if (!initialPath) {
51+
initialPath = locationToString(location);
52+
}
53+
4654
// Avoid dispatching an action if the store is already up-to-date,
4755
// even if `history` wouldn't do anthing if the location is the same
4856
if(store.getState().routing.path !== locationToString(location)) {
@@ -52,6 +60,13 @@ function syncReduxAndRouter(history, store) {
5260

5361
store.subscribe(() => {
5462
const routing = store.getState().routing;
63+
64+
// Catch when devtools has 'RESET' the state and force
65+
// navigation back to the initial location
66+
if (routing.path === undefined) {
67+
routing.path = initialPath;
68+
}
69+
5570
// Don't update the router is nothing has changed. The
5671
// `avoidRouterUpdate` flag can be set to avoid updating altogether,
5772
// which is useful for things like loading snapshots or very special

0 commit comments

Comments
 (0)