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

Commit b2c2259

Browse files
authored
Don't call the listener with history 3
1 parent b16a678 commit b2c2259

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/sync.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export default function syncHistoryWithStore(history, store, {
9797
}
9898
unsubscribeFromHistory = history.listen(handleLocationChange)
9999

100-
// support history 3.x
101-
if(history.getCurrentLocation) {
100+
// History 3.x doesn't call listen synchronously, so fire the initial location change ourselves
101+
if (history.getCurrentLocation) {
102102
handleLocationChange(history.getCurrentLocation())
103103
}
104104

@@ -124,10 +124,12 @@ export default function syncHistoryWithStore(history, store, {
124124
}
125125
})
126126

127-
// History listeners expect a synchronous call. Make the first call to the
127+
// History 2.x listeners expect a synchronous call. Make the first call to the
128128
// listener after subscribing to the store, in case the listener causes a
129129
// location change (e.g. when it redirects)
130-
listener(lastPublishedLocation)
130+
if (!history.getCurrentLocation) {
131+
listener(lastPublishedLocation)
132+
}
131133

132134
// Let user unsubscribe later
133135
return () => {

0 commit comments

Comments
 (0)