Fix blog route conflict that crashed the Next.js server.
Rename legacy /blog/[slug] redirect to /blog/[id] so it matches the nested [id]/[slug] segment name. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
0cb9aa57e2
commit
5d53cf91eb
@@ -4,18 +4,18 @@ import { getBlogPost } from "@/lib/data";
|
|||||||
|
|
||||||
export const revalidate = 60;
|
export const revalidate = 60;
|
||||||
|
|
||||||
/** Legacy `/blog/{slug}` → canonical `/blog/{id}/{titleSlug}`. */
|
/** Legacy `/blog/{slug-or-id}` → canonical `/blog/{id}/{titleSlug}`. */
|
||||||
export default async function LegacyBlogRedirect({
|
export default async function LegacyBlogRedirect({
|
||||||
params,
|
params,
|
||||||
}: {
|
}: {
|
||||||
params: Promise<{ slug: string }>;
|
params: Promise<{ id: string }>;
|
||||||
}) {
|
}) {
|
||||||
const { slug } = await params;
|
const { id } = await params;
|
||||||
|
|
||||||
const apiPost = await fetchBlogBySlug(slug);
|
const apiPost = await fetchBlogBySlug(id);
|
||||||
if (apiPost) redirect(blogHref(apiPost));
|
if (apiPost) redirect(blogHref(apiPost));
|
||||||
|
|
||||||
const local = getBlogPost(slug);
|
const local = getBlogPost(id);
|
||||||
if (local) redirect(blogHref({ id: local.slug, title: local.title }));
|
if (local) redirect(blogHref({ id: local.slug, title: local.title }));
|
||||||
|
|
||||||
notFound();
|
notFound();
|
||||||
Reference in New Issue
Block a user