import { NextResponse } from "next/server";
export async function GET(request, route) {
const id = route.params.id;
console.log('req',id)
return NextResponse.json({ success: true, id:id });
}
쉽게 코드 복사하라고 텍스트도 넣어둔다.
코드 설명을 간단히 하면,http://localhost:3000/api/address/[ID]
http://localhost:3000/api/address/12345
뒤에 12345, id에 해당하는 값을 읽어오는 코드이다.
이걸 하기 위해서는 폴더 구조를 아래처럼 하면 된다.
'개발로 부자되기 > next.js' 카테고리의 다른 글
next js router 페이지간 query 전달하기 2가지 방법, 예시 (0) | 2023.12.10 |
---|---|
next 13 auth firebase google login 해결법 (vercel 배포까지) (0) | 2023.09.29 |
react-table 너비 (width) 조정하기, 예제코드 (0) | 2023.08.31 |
해결법 Next.js error cannot find module 'next/headers' (0) | 2023.08.15 |
next.js에서 버튼 누를 시, url 이동하기 리디랙션(redirect) (0) | 2023.07.17 |