Skip to content

Commit 50d370b

Browse files
fix: correct route on reset search button click
1 parent 40bda37 commit 50d370b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

client-app/shared/catalog/components/category.vue

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ import {
231231
import omit from "lodash/omit";
232232
import { computed, defineAsyncComponent, onBeforeUnmount, onMounted, ref, shallowRef, toRef, toRefs, watch } from "vue";
233233
import { useI18n } from "vue-i18n";
234-
import { useRoute } from "vue-router";
234+
import { useRoute, useRouter } from "vue-router";
235235
import { useAnalytics, useThemeContext } from "@/core/composables";
236236
import { useLanguages } from "@/core/composables/useLanguages";
237237
import { useModuleSettings } from "@/core/composables/useModuleSettings";
@@ -257,6 +257,7 @@ import ProductsFilters from "./products-filters.vue";
257257
import ViewMode from "./view-mode.vue";
258258
import type { Product } from "@/core/api/graphql/types";
259259
import type { FiltersDisplayOrderType, ProductsFiltersType, ProductsSearchParamsType } from "@/shared/catalog";
260+
import type { RouteLocationRaw } from "vue-router";
260261
import ActiveFilterChips from "@/shared/catalog/components/active-filter-chips.vue";
261262
import CategoryControls from "@/shared/catalog/components/category/category-controls.vue";
262263
import CategoryHorizontalFilters from "@/shared/catalog/components/category/category-horizontal-filters.vue";
@@ -306,6 +307,7 @@ const isMobile = breakpoints.smaller("md");
306307
const isCategoryNotFound = ref(false);
307308
308309
const route = useRoute();
310+
const router = useRouter();
309311
310312
const normalizedFacetsToHide = computed(() => {
311313
return facetsToHide.value?.map((facet) => facet.toLowerCase());
@@ -537,8 +539,33 @@ function resetPage() {
537539
}
538540
539541
function handleResetFilterKeyword() {
542+
const back = router.options.history.state?.back;
543+
544+
if (!back) {
545+
resetSearchKeyword();
546+
return;
547+
}
548+
549+
if (isRouteLocationRaw(back)) {
550+
const previousResolvedRoute = router.resolve(back);
551+
if (previousResolvedRoute.matched.length > 0) {
552+
void router.push(previousResolvedRoute);
553+
return;
554+
}
555+
}
556+
540557
resetSearchKeyword();
541-
resetFacetFilters();
558+
}
559+
560+
function isRouteLocationRaw(value: unknown): value is RouteLocationRaw {
561+
if (typeof value === "string") {
562+
return true;
563+
}
564+
if (typeof value === "object" && value !== null) {
565+
const record = value as Record<string, unknown>;
566+
return "path" in record || "name" in record;
567+
}
568+
return false;
542569
}
543570
544571
whenever(() => !isMobile.value, hideFiltersSidebar);

0 commit comments

Comments
 (0)