From c0d3376f4e3527bd761bd325873366ed74f5736b Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 23 Oct 2019 08:08:31 -0700 Subject: [PATCH] feat(history): preserve existing history.state Closes #3006 --- src/util/push-state.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/push-state.js b/src/util/push-state.js index 823c98dc4..c5dda83e1 100644 --- a/src/util/push-state.js +++ b/src/util/push-state.js @@ -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 && @@ -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) }