summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/url_sync.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/url_sync.vue')
-rw-r--r--app/assets/javascripts/vue_shared/components/url_sync.vue17
1 files changed, 15 insertions, 2 deletions
diff --git a/app/assets/javascripts/vue_shared/components/url_sync.vue b/app/assets/javascripts/vue_shared/components/url_sync.vue
index 925c6008836..bd5b7b77017 100644
--- a/app/assets/javascripts/vue_shared/components/url_sync.vue
+++ b/app/assets/javascripts/vue_shared/components/url_sync.vue
@@ -1,6 +1,9 @@
<script>
import { historyPushState } from '~/lib/utils/common_utils';
-import { mergeUrlParams } from '~/lib/utils/url_utility';
+import { mergeUrlParams, setUrlParams } from '~/lib/utils/url_utility';
+
+export const URL_SET_PARAMS_STRATEGY = 'set';
+export const URL_MERGE_PARAMS_STRATEGY = 'merge';
/**
* Renderless component to update the query string,
@@ -15,6 +18,12 @@ export default {
required: false,
default: null,
},
+ urlParamsUpdateStrategy: {
+ type: String,
+ required: false,
+ default: URL_MERGE_PARAMS_STRATEGY,
+ validator: (value) => [URL_MERGE_PARAMS_STRATEGY, URL_SET_PARAMS_STRATEGY].includes(value),
+ },
},
watch: {
query: {
@@ -29,7 +38,11 @@ export default {
},
methods: {
updateQuery(newQuery) {
- historyPushState(mergeUrlParams(newQuery, window.location.href, { spreadArrays: true }));
+ const url =
+ this.urlParamsUpdateStrategy === URL_SET_PARAMS_STRATEGY
+ ? setUrlParams(this.query, window.location.href, true)
+ : mergeUrlParams(newQuery, window.location.href, { spreadArrays: true });
+ historyPushState(url);
},
},
render() {