@@ -61,6 +61,8 @@ function locationsAreEqual(a, b) {
61
61
function syncReduxAndRouter ( history , store , selectRouterState = SELECT_STATE ) {
62
62
const getRouterState = ( ) => selectRouterState ( store . getState ( ) ) ;
63
63
let lastChangeId = 0 ;
64
+ let firstRoute = undefined ;
65
+ let lastRoute = { } ;
64
66
65
67
if ( ! getRouterState ( ) ) {
66
68
throw new Error (
@@ -75,10 +77,17 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
75
77
state : location . state
76
78
} ;
77
79
80
+ if ( firstRoute === undefined ) {
81
+ firstRoute = route ;
82
+ }
83
+ console . log ( 'HISTORY' , route ) ;
84
+
78
85
// Avoid dispatching an action if the store is already up-to-date,
79
86
// even if `history` wouldn't do anything if the location is the same
80
87
if ( locationsAreEqual ( getRouterState ( ) , route ) ) return ;
81
88
89
+ lastRoute = route ;
90
+
82
91
const updatePath = location . action === 'REPLACE'
83
92
? replacePath
84
93
: pushPath ;
@@ -87,14 +96,22 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) {
87
96
} ) ;
88
97
89
98
const unsubscribeStore = store . subscribe ( ( ) => {
90
- const routing = getRouterState ( ) ;
99
+ let routing = getRouterState ( ) ;
100
+ console . log ( 'STORE' , routing ) ;
101
+
102
+ if ( routing === initialState ) {
103
+ routing = firstRoute ;
104
+ }
91
105
92
106
// Only update the router once per `pushPath` call. This is
93
107
// indicated by the `changeId` state; when that number changes, we
94
108
// should update the history.
95
- if ( lastChangeId === routing . changeId ) return ;
109
+ if ( lastChangeId === routing . changeId ) {
110
+ if ( locationsAreEqual ( routing , lastRoute ) ) return ;
111
+ }
96
112
97
113
lastChangeId = routing . changeId ;
114
+ lastRoute = routing ;
98
115
99
116
const method = routing . replace ? 'replaceState' : 'pushState' ;
100
117
0 commit comments