Skip to content

Commit ed25816

Browse files
Yushin-Lclaude
andcommitted
Fix tag click 404: link TagBadge to /posts?tag= filter
- TagBadge now links to /posts?tag=<tag> instead of /tags/<tag>/ - SupabasePostsWithFilter reads ?tag query param for initial filter - Wrap with Suspense for useSearchParams compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7ea5473 commit ed25816

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/app/posts/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { Suspense } from "react";
12
import SupabasePostsWithFilter from "@/components/posts/SupabasePostsWithFilter";
23

34
export default function AllPostsPage() {
45
return (
56
<>
67
<h1 className="mb-8 text-2xl font-bold text-stone-900">전체 글</h1>
7-
<SupabasePostsWithFilter />
8+
<Suspense>
9+
<SupabasePostsWithFilter />
10+
</Suspense>
811
</>
912
);
1013
}

src/components/posts/SupabasePostsWithFilter.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useEffect, useState } from "react";
4+
import { useSearchParams } from "next/navigation";
45
import { getPublishedPosts } from "@/lib/drafts/published";
56
import type { Post } from "@/types/post";
67
import type { PostDraft } from "@/lib/supabase/types";
@@ -28,9 +29,11 @@ function draftToPost(draft: PostDraft): Post {
2829
}
2930

3031
export default function SupabasePostsWithFilter() {
32+
const searchParams = useSearchParams();
33+
const initialTag = searchParams.get("tag");
3134
const [posts, setPosts] = useState<Post[]>([]);
3235
const [loading, setLoading] = useState(true);
33-
const [selectedTag, setSelectedTag] = useState<string | null>(null);
36+
const [selectedTag, setSelectedTag] = useState<string | null>(initialTag);
3437

3538
useEffect(() => {
3639
getPublishedPosts()

src/components/posts/TagBadge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface TagBadgeProps {
77
export default function TagBadge({ tag }: TagBadgeProps) {
88
return (
99
<Link
10-
href={`/tags/${tag}/`}
10+
href={`/posts?tag=${encodeURIComponent(tag)}`}
1111
className="inline-block rounded-full bg-indigo-50 px-3 py-1 text-xs font-medium text-indigo-600 transition-colors hover:bg-indigo-100"
1212
>
1313
{tag}

0 commit comments

Comments
 (0)