소스코드
https://github.com/egoing/nextapp/commit/d3d1d4f9749250065f7032f939acb01a1bb9af3a
절차
1. app/Control.js 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | "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> ); <font face= "NanumGothic, sans-serif" ><span style= "font-size: 10.89px; white-space: normal;" > </span></font> |