Skip to content

Commit c0d3376

Browse files
committed
feat(history): preserve existing history.state
Closes #3006
1 parent 23d87d8 commit c0d3376

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/util/push-state.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { inBrowser } from './dom'
44
import { saveScrollPosition } from './scroll'
55
import { genStateKey, setStateKey, getStateKey } from './state-key'
6+
import { extend } from './misc'
67

78
export const supportsPushState =
89
inBrowser &&
@@ -28,7 +29,10 @@ export function pushState (url?: string, replace?: boolean) {
2829
const history = window.history
2930
try {
3031
if (replace) {
31-
history.replaceState({ key: getStateKey() }, '', url)
32+
// preserve existing history state as it could be overriden by the user
33+
const stateCopy = extend({}, history.state)
34+
stateCopy.key = getStateKey()
35+
history.replaceState(stateCopy, '', url)
3236
} else {
3337
history.pushState({ key: setStateKey(genStateKey()) }, '', url)
3438
}

0 commit comments

Comments
 (0)