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
@@ -0,0 +1,22 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { blogHref, fetchBlogBySlug } from "@/lib/blog";
|
||||
import { getBlogPost } from "@/lib/data";
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
/** Legacy `/blog/{slug-or-id}` → canonical `/blog/{id}/{titleSlug}`. */
|
||||
export default async function LegacyBlogRedirect({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
|
||||
const apiPost = await fetchBlogBySlug(id);
|
||||
if (apiPost) redirect(blogHref(apiPost));
|
||||
|
||||
const local = getBlogPost(id);
|
||||
if (local) redirect(blogHref({ id: local.slug, title: local.title }));
|
||||
|
||||
notFound();
|
||||
}
|
||||
Reference in New Issue
Block a user