Resolve pages via by-id APIs, slugify Farsi titles for public paths, and redirect legacy slug-only URLs to the canonical form. Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
637 B
TypeScript
27 lines
637 B
TypeScript
import { notFound, redirect } from "next/navigation";
|
|
import {
|
|
catalogTitle,
|
|
fetchCatalogProductById,
|
|
fetchCatalogProductBySlug,
|
|
productHref,
|
|
} from "@/lib/store";
|
|
|
|
export const revalidate = 60;
|
|
|
|
/** Legacy `/products/{id-or-slug}` → canonical `/products/{id}/{nameFaSlug}`. */
|
|
export default async function LegacyProductRedirect({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
}) {
|
|
const { id } = await params;
|
|
|
|
const byId = await fetchCatalogProductById(id);
|
|
if (byId) redirect(productHref(byId));
|
|
|
|
const bySlug = await fetchCatalogProductBySlug(id);
|
|
if (bySlug) redirect(productHref(bySlug));
|
|
|
|
notFound();
|
|
}
|