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

Commit

Permalink
Don't call the listener with history 3
Browse files Browse the repository at this point in the history
  • Loading branch information
timdorr committed Feb 8, 2017
1 parent b16a678 commit b2c2259
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/sync.js
Expand Up @@ -97,8 +97,8 @@ export default function syncHistoryWithStore(history, store, {
}
unsubscribeFromHistory = history.listen(handleLocationChange)

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

Expand All @@ -124,10 +124,12 @@ export default function syncHistoryWithStore(history, store, {
}
})

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

// Let user unsubscribe later
return () => {
Expand Down

0 comments on commit b2c2259

Please sign in to comment.