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)); -}