From 911aa7953066c1b57ecac29f123a9c8096f0f11c Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Tue, 15 Sep 2026 15:50:09 +0330 Subject: [PATCH] Fix Next dynamic route conflict that crashed the whole site. Use matching [id] segment names for one- and two-segment user-product paths so standalone no longer throws on every request. Co-authored-by: Cursor --- src/app/user-products/[id]/page.tsx | 27 +++++++++++++++++++++++++++ src/app/user-products/[slug]/page.tsx | 17 ----------------- 2 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/app/user-products/[id]/page.tsx delete mode 100644 src/app/user-products/[slug]/page.tsx diff --git a/src/app/user-products/[id]/page.tsx b/src/app/user-products/[id]/page.tsx new file mode 100644 index 0000000..ac9e19d --- /dev/null +++ b/src/app/user-products/[id]/page.tsx @@ -0,0 +1,27 @@ +import { notFound, redirect } from "next/navigation"; +import { + getUserProductByIdOrNull, + getUserProductBySlugOrNull, + userProductHref, +} from "@/lib/api/user-products"; + +type PageProps = { + params: Promise<{ id: string }>; +}; + +/** + * One-segment `/user-products/{idOrLegacySlug}`: + * - numeric/id → load by-id and redirect to canonical `/user-products/{id}/{pathSlug}` + * - legacy DB slug (e.g. user-product-5) → same redirect + */ +export default async function UserProductIdRedirect({ params }: PageProps) { + const { id } = await params; + + const byId = await getUserProductByIdOrNull(id); + if (byId) redirect(userProductHref(byId)); + + const bySlug = await getUserProductBySlugOrNull(id); + if (bySlug) redirect(userProductHref(bySlug)); + + notFound(); +} diff --git a/src/app/user-products/[slug]/page.tsx b/src/app/user-products/[slug]/page.tsx deleted file mode 100644 index 14a0789..0000000 --- a/src/app/user-products/[slug]/page.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { notFound, redirect } from "next/navigation"; -import { - getUserProductBySlugOrNull, - userProductHref, -} from "@/lib/api/user-products"; - -type PageProps = { - params: Promise<{ slug: string }>; -}; - -/** Legacy `/user-products/{db-slug}` → canonical `/user-products/{id}/{pathSlug}`. */ -export default async function LegacyUserProductRedirect({ params }: PageProps) { - const { slug } = await params; - const product = await getUserProductBySlugOrNull(slug); - if (!product) notFound(); - redirect(userProductHref(product)); -}