Skip to content

Commit e68bab9

Browse files
committed
fix: slug
1 parent 290acfb commit e68bab9

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

app/(public)/blog/[id]/page.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/(public)/blog/[slug]/page.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import BlogDeatails from "@/components/blog/details";
2+
import { blogData } from "@/static/blog";
3+
export async function generateStaticParams() {
4+
return blogData.map((post) => ({
5+
slug: post.id,
6+
}));
7+
}
8+
9+
export default function Page({
10+
params: { slug },
11+
}: {
12+
params: { slug: string };
13+
}) {
14+
return <BlogDeatails id={slug} />;
15+
}

components/blog/details/index.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
"use client";
22

3-
import React, { useEffect, useState } from "react";
4-
import { useParams } from "next/navigation";
53
import { blogData } from "@/static/blog";
64
import { BlogItem } from "@/types/blog";
7-
import DetailHero from "./DetailHero";
5+
import { useEffect, useState } from "react";
86
import DetailContent from "./DetailContent";
7+
import DetailHero from "./DetailHero";
98

10-
const BlogDeatails = () => {
11-
const params = useParams(); // get id from URL
9+
const BlogDetails = ({ id }: { id: string }) => {
1210
const [post, setPost] = useState<BlogItem | null>(null);
1311

1412
useEffect(() => {
15-
if (params?.id) {
16-
const found = blogData.find((b) => b.id.toString() === params.id);
13+
if (id) {
14+
const found = blogData.find((b) => b.id.toString() === id);
1715
setPost(found || null);
1816
}
19-
}, [params?.id]);
17+
}, [id]);
2018

2119
if (!post) return <div>Loading or blog not found...</div>;
2220

@@ -30,9 +28,10 @@ const BlogDeatails = () => {
3028
date={post.author.date}
3129
readTime={post.author.readTime}
3230
/>
31+
3332
<DetailContent content={post.content} />
3433
</div>
3534
);
3635
};
3736

38-
export default BlogDeatails;
37+
export default BlogDetails;

0 commit comments

Comments
 (0)