Skip to content

Commit 5b83a97

Browse files
authored
fix(core): pass searchParams when swapping locales (#2362)
1 parent 7ba8a9a commit 5b83a97

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

.changeset/rich-brooms-read.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@bigcommerce/catalyst-core": patch
3+
---
4+
5+
Pass search params to router.redirect when swapping locales.
6+
7+
## Migration
8+
9+
Modify `useSwitchLocale` hook to include `Object.fromEntries(searchParams.entries())`.

core/vibes/soul/primitives/navigation/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as Popover from '@radix-ui/react-popover';
77
import { clsx } from 'clsx';
88
import debounce from 'lodash.debounce';
99
import { ArrowRight, ChevronDown, Search, SearchIcon, ShoppingBag, User } from 'lucide-react';
10-
import { useParams } from 'next/navigation';
10+
import { useParams, useSearchParams } from 'next/navigation';
1111
import React, {
1212
forwardRef,
1313
Ref,
@@ -829,17 +829,18 @@ const useSwitchLocale = () => {
829829
const pathname = usePathname();
830830
const router = useRouter();
831831
const params = useParams();
832+
const searchParams = useSearchParams();
832833

833834
return useCallback(
834835
(locale: string) =>
835836
router.push(
836837
// @ts-expect-error -- TypeScript will validate that only known `params`
837838
// are used in combination with a given `pathname`. Since the two will
838839
// always match for the current route, we can skip runtime checks.
839-
{ pathname, params },
840+
{ pathname, params, query: Object.fromEntries(searchParams.entries()) },
840841
{ locale },
841842
),
842-
[pathname, params, router],
843+
[pathname, params, router, searchParams],
843844
);
844845
};
845846

0 commit comments

Comments
 (0)