Skip to content

Commit

Permalink
feat(history): preserve existing history.state
Browse files Browse the repository at this point in the history
Closes #3006
  • Loading branch information
posva committed Oct 23, 2019
1 parent 23d87d8 commit c0d3376
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util/push-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { inBrowser } from './dom'
import { saveScrollPosition } from './scroll'
import { genStateKey, setStateKey, getStateKey } from './state-key'
import { extend } from './misc'

export const supportsPushState =
inBrowser &&
Expand All @@ -28,7 +29,10 @@ export function pushState (url?: string, replace?: boolean) {
const history = window.history
try {
if (replace) {
history.replaceState({ key: getStateKey() }, '', url)
// preserve existing history state as it could be overriden by the user
const stateCopy = extend({}, history.state)
stateCopy.key = getStateKey()
history.replaceState(stateCopy, '', url)
} else {
history.pushState({ key: setStateKey(genStateKey()) }, '', url)
}
Expand Down

1 comment on commit c0d3376

@ksurakka
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and thx!

Please sign in to comment.