Skip to content

Commit

Permalink
Router push needs a catch block, as navigating to same route throws a…
Browse files Browse the repository at this point in the history
…n error, see vuejs/vue-router#2881 (comment). It seems it's not supposed to throw the error if parameters are changed, so maybe a bug in vue-router?
  • Loading branch information
lfarrell committed Apr 28, 2020
1 parent 72b4e4f commit 657fc11
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
7 changes: 6 additions & 1 deletion static/js/vue-cdr-access/src/components/browseSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
methods: {
getResults() {
let update_params = { anywhere: encodeURIComponent(this.search_query) };
this.$router.push({ name: 'displayRecords', query: this.urlParams(update_params) });
this.$router.push({ name: 'displayRecords', query: this.urlParams(update_params) })
.catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
},
clearSearch() {
Expand Down
4 changes: 4 additions & 0 deletions static/js/vue-cdr-access/src/components/browseSort.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
this.$router.push({
path: this.$route.path,
query: this.urlParams({ sort: this.sort_order }, is_search_sort)
}).catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
this.sort_order = '';
}
Expand Down
6 changes: 5 additions & 1 deletion static/js/vue-cdr-access/src/components/displayWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
updateUrl() {
let params = this.setTypes();
this.$router.push({ name: 'displayRecords', query: params });
this.$router.push({ name: 'displayRecords', query: params }).catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
},
updateParams() {
Expand Down
6 changes: 5 additions & 1 deletion static/js/vue-cdr-access/src/components/facets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@
// Add/Update with new facets
base_search.query = Object.assign(base_search.query, updated_facet_params.queryFacets);
this.$router.push(base_search);
this.$router.push(base_search).catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
},
/**
Expand Down
6 changes: 5 additions & 1 deletion static/js/vue-cdr-access/src/components/viewType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
e.preventDefault();
this.browse_type = e.target.id;
let update_params = { browse_type: encodeURIComponent(this.browse_type) };
this.$router.push({ name: 'displayRecords', query: this.urlParams(update_params) });
this.$router.push({ name: 'displayRecords', query: this.urlParams(update_params) }).catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
sessionStorage.setItem('browse-type', this.browse_type);
}
},
Expand Down
6 changes: 5 additions & 1 deletion static/js/vue-cdr-access/src/components/worksOnly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
params.types = this.updateWorkType(this.adminUnit, this.works_only).types;
params.works_only = this.works_only;
this.$router.push({ name: 'displayRecords', query: params });
this.$router.push({ name: 'displayRecords', query: params }).catch((e) => {
if (e.name !== 'NavigationDuplicated') {
throw e;
}
});
}
},
Expand Down

0 comments on commit 657fc11

Please sign in to comment.