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 <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-15 15:50:09 +03:30
co-authored by Cursor
parent 5a6ef9e0e0
commit 911aa79530
2 changed files with 27 additions and 17 deletions
+27
View File
@@ -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();
}
-17
View File
@@ -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));
}