Skip to content

Commit

Permalink
Merge pull request #26 from supasate/handle-search-and-hash-in-time-t…
Browse files Browse the repository at this point in the history
…ravelling

Handle changes of search and hash location in time travelling
  • Loading branch information
supasate authored Jan 19, 2017
2 parents d53f289 + bbce69b commit af80154
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/ConnectedRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ export class ConnectedRouter extends Component {

// Subscribe to store changes
this.unsubscribe = context.store.subscribe(() => {
const locationInStore = context.store.getState().router.location.pathname
const locationInHistory = props.history.location.pathname
// Extract store's location
const {
pathname: pathnameInStore,
search: searchInStore,
hash: hashInStore,
} = context.store.getState().router.location

// Extract history's location
const {
pathname: pathnameInHistory,
search: searchInHistory,
hash: hashInHistory,
} = props.history.location

// If we do time travelling, the location in store is changed but location in history is not changed
if (locationInHistory !== locationInStore) {
if (pathnameInHistory !== pathnameInStore || searchInHistory !== searchInStore || hashInHistory !== hashInStore) {
this.inTimeTravelling = true
// Update history's location to match store's location
props.history.push(locationInStore)
props.history.push({
pathname: pathnameInStore,
search: searchInStore,
hash: hashInStore,
})
}
})

Expand Down

0 comments on commit af80154

Please sign in to comment.