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

only update on location changes #269

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ export function syncHistory(history) {
unsubscribeStore = store.subscribe(() => {
const location = getLocationState()

// If we're resetting to the beginning, use the saved initial value. We
// need to dispatch a new action at this point to populate the store
// appropriately.
if (location.key === initialLocation.key) {
history.replace(initialLocation)
return
}

// Otherwise, if we need to update the history location, do so without
// dispatching a new action, as we're just bringing history in sync
// with the store.
// Only update on location changes
if (location.key !== currentKey) {

// If we're resetting to the beginning, use the saved initial value. We
// need to dispatch a new action at this point to populate the store
// appropriately.
if (location.key === initialLocation.key) {
history.replace(initialLocation)
return
}

// Otherwise, if we need to update the history location, do so without
// dispatching a new action, as we're just bringing history in sync
// with the store.
syncing = true
history.transitionTo(location)
syncing = false
Expand Down