소스코드
https://github.com/egoing/nextapp/commit/d3d1d4f9749250065f7032f939acb01a1bb9af3a
절차
1. app/Control.js 수정
"use client";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
export function Control() {
const router = useRouter();
const params = useParams();
const id = params.id;
return (
<ul>
<li>
<Link href="/create">create</Link>
</li>
{id ? (
<>
<li>
<Link href={`/update/${id}`}>update</Link>
</li>
<li>
<button onClick={async ()=>{
const resp = await fetch(`http://localhost:9999/topics/${id}`, {
method: 'DELETE',
});
await resp.json();
router.push('/');
router.refresh();
}}>delete</button>
</li>
</>
) : null}
</ul>
);