export default function CategoriesPage() {
return (
<ul>
<li>Technology</li>
<li>Travel</li>
<li>Food</li>
</ul>
);
}
export default function WelcomePostPage() {
return (
<div>
<h1>Welcome to our Blog!</h1>
<p>This is an introductory post...</p>
</div>
)
}
async function getPost(slug: string) {
const res = await fetch(`https://api.example.com/posts/${slug}`);
if (!res.ok) {
throw new Error('Failed to fetch post');
}
return res.json();
}
export default async function PostPage({ params }: { params: { slug: string } }) {
const post = await getPost(params.slug);
return (
<div>
<h1>{post.title}</h1>
<p>Views: {post.views}</p> <narration>Dynamic view count</narration>
<p>{post.content}</p>
</div>
);
}
import { useSearchParams } from 'next/navigation'
async function getPosts(tag: string) {
let url = `https://api.example.com/posts?tag=${tag}`
const res = await fetch(url);
return res.json();
}
export default async function BlogPage() {
const tag = useSearchParams().get('tag')
const posts = await getPosts(tag)
return (
<ul>
{posts.map(post => (
<li key={post.slug}><a href={`/blog/${post.slug}`}>{post.title}</a></li>
))}
</ul>
)
}