I have a search using nuxt-apollo. If I search a product and then navigate to it's corresponding page from search and decide to go back to search, search results reset to what was initially returned before search.
I assume this is a cache-related thing, and would like to figure out how to keep new search results cached.
Is the solution to use Vuex to store the results? Or is there some simple cache update function I can use within Apollo?
search.vue
// apollo search
apollo: {
products: {
query: filteredProducts,
loadingKey: 'loading',
variables() {
return {
query: this.query.queryString,
first: this.resultsCount,
sortKey: this.query.sorting,
reverse: this.query.reverse,
afterItemCursor: null,
}
},
result(data) {
return data.products
}
}
},
// update search method
updateSearch() {
// update search parameters triggering an auto refetch from nuxt-apollo
this.filterDialogOpen = false
this.query.queryString = this.formatQuery
this.query.sorting = this.selectedSortingOption.value
this.query.reverse = this.selectedSortingOption.reverse
// push formatted query to router query
this.$router.push({
query: {
search: this.formatQuery
}
})
}
Before you mark this as duplicate... It's worth noting that nuxt-apollo is built on vue-apollo but with some additional quirks here and there. I have no problem accomplishing this in my other projects by updating the router query, and the results cache... but nuxt-apollo seems to function differently in that regard. Any help is appreciated, thanks!