@@ -231,7 +231,7 @@ import {
231231import omit from " lodash/omit" ;
232232import { computed , defineAsyncComponent , onBeforeUnmount , onMounted , ref , shallowRef , toRef , toRefs , watch } from " vue" ;
233233import { useI18n } from " vue-i18n" ;
234- import { useRoute } from " vue-router" ;
234+ import { useRoute , useRouter } from " vue-router" ;
235235import { useAnalytics , useThemeContext } from " @/core/composables" ;
236236import { useLanguages } from " @/core/composables/useLanguages" ;
237237import { useModuleSettings } from " @/core/composables/useModuleSettings" ;
@@ -257,6 +257,7 @@ import ProductsFilters from "./products-filters.vue";
257257import ViewMode from " ./view-mode.vue" ;
258258import type { Product } from " @/core/api/graphql/types" ;
259259import type { FiltersDisplayOrderType , ProductsFiltersType , ProductsSearchParamsType } from " @/shared/catalog" ;
260+ import type { RouteLocationRaw } from " vue-router" ;
260261import ActiveFilterChips from " @/shared/catalog/components/active-filter-chips.vue" ;
261262import CategoryControls from " @/shared/catalog/components/category/category-controls.vue" ;
262263import CategoryHorizontalFilters from " @/shared/catalog/components/category/category-horizontal-filters.vue" ;
@@ -306,6 +307,7 @@ const isMobile = breakpoints.smaller("md");
306307const isCategoryNotFound = ref (false );
307308
308309const route = useRoute ();
310+ const router = useRouter ();
309311
310312const normalizedFacetsToHide = computed (() => {
311313 return facetsToHide .value ?.map ((facet ) => facet .toLowerCase ());
@@ -537,8 +539,33 @@ function resetPage() {
537539}
538540
539541function 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
544571whenever (() => ! isMobile .value , hideFiltersSidebar );
0 commit comments