diff --git a/src/app/catalog/[slug]/page.tsx b/src/app/product/[...productParams]/page.tsx similarity index 85% rename from src/app/catalog/[slug]/page.tsx rename to src/app/product/[...productParams]/page.tsx index 738b9c7b..93088d1d 100644 --- a/src/app/catalog/[slug]/page.tsx +++ b/src/app/product/[...productParams]/page.tsx @@ -5,11 +5,12 @@ import CoreLayout from "@/components/layouts/CoreLayout"; import AddToCartButton from "@/components/productPage/AddToCartButton"; import { CURRENCY_MAP, MAX_LIMIT } from "@/constants"; import { serviceClient } from "@/lib/api"; +import { notFound } from "next/navigation"; import { Suspense } from "react"; interface ProductPageProps { params: { - slug: string; + productParams: string[]; }; } @@ -24,7 +25,7 @@ export async function generateStaticParams() { return ( response.products?.map((product) => ({ - slug: product.slug!, + slug: product.slug?.replace("product/", "").split("/") || [], })) || [] ); } @@ -35,10 +36,19 @@ const catalogData = [ ]; export default async function ProductPage({ params }: ProductPageProps) { - const { slug } = params; + const { productParams } = params; + + if (productParams.length !== 4) { + return notFound(); + } + + const [gender, brand, name, id] = productParams; const { product } = await serviceClient.GetProduct({ - slug, + gender, + brand, + name, + id: parseInt(id), }); return ( @@ -73,8 +83,8 @@ export default async function ProductPage({ params }: ProductPageProps) { {/* TO-DO pass size from form */} diff --git a/src/components/cart/CartItemRow.tsx b/src/components/cart/CartItemRow.tsx index 54f0b503..cd1e136a 100644 --- a/src/components/cart/CartItemRow.tsx +++ b/src/components/cart/CartItemRow.tsx @@ -26,7 +26,7 @@ export default function CartItemRow({
{ - const response = await serviceClient.GetProduct({ slug: item.slug }); + const [gender, brand, name, id] = item.slug.split("/"); + const response = await serviceClient.GetProduct({ + gender, + brand, + name, + id: parseInt(id), + }); const product = response.product; return { @@ -36,7 +42,7 @@ export default async function CartProductsList() { return products.map((p) => (