mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 17:25:53 +00:00
This reverts commit 7dc7e6d6e45facc0a7b3ed1816ea123fa6aac84e.
This commit is contained in:
parent
7dc7e6d6e4
commit
61b134a66c
@ -4,7 +4,7 @@ import clsx from 'clsx';
|
|||||||
import { ProductOption, ProductVariant } from 'lib/shopify/types';
|
import { ProductOption, ProductVariant } from 'lib/shopify/types';
|
||||||
import { createUrl } from 'lib/utils';
|
import { createUrl } from 'lib/utils';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { redirect, usePathname, useSearchParams } from 'next/navigation';
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
type ParamsMap = {
|
type ParamsMap = {
|
||||||
[key: string]: string; // ie. { color: 'Red', size: 'Large', ... }
|
[key: string]: string; // ie. { color: 'Red', size: 'Large', ... }
|
||||||
@ -26,6 +26,7 @@ export function VariantSelector({
|
|||||||
}) {
|
}) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const currentParams = useSearchParams();
|
const currentParams = useSearchParams();
|
||||||
|
const router = useRouter();
|
||||||
const hasNoOptionsOrJustOneOption =
|
const hasNoOptionsOrJustOneOption =
|
||||||
!options.length || (options.length === 1 && options[0]?.values.length === 1);
|
!options.length || (options.length === 1 && options[0]?.values.length === 1);
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ export function VariantSelector({
|
|||||||
const selectedVariantUrl = createUrl(pathname, selectedVariantParams);
|
const selectedVariantUrl = createUrl(pathname, selectedVariantParams);
|
||||||
|
|
||||||
if (currentUrl !== selectedVariantUrl) {
|
if (currentUrl !== selectedVariantUrl) {
|
||||||
redirect(selectedVariantUrl);
|
router.replace(selectedVariantUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.map((option) => (
|
return options.map((option) => (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user