정적 생성 질무우우우운!!!!!!!!!!!!!!!!!!!(꼭 답해주세요) #79
gayeong0916
started this conversation in
General
Replies: 1 comment 1 reply
-
|
Next.js 앱라우터에서의 정적생성
// app/posts/[id]/page.tsx
export async function generateStaticParams() {
// 정적으로 생성할 동적 경로 정의: 페이지 파일에 적어 놨어요...!
const paths = [
{ id: '1' },
{ id: '2' },
];
return paths.map((path) => ({
id: path.id,
}));
}
const Post = async ({ params }) => { ==> 이 const { id } = params;
// 정적으로 생성된 데이터 가져오기
const res = await axios.get(`https://api.example.com/posts/${id}`);
const post = res.data;
return (
<div>
<h1>{post.title}</h1>
<p>{post.content}</p>
<Comments postId={id} /> {/* 클라이언트 컴포넌트 */}
</div> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
저기서 동그라미 친 부분들 빼고 정적 생성을 하라는 의견을 듣고 tanstack 리액트 쿼리를 사용해서
정적 생성을 하려고 하는데 getStaticProps()를 사용하라는 뜻이 맞는지 여쭤보고 싶슴다
Beta Was this translation helpful? Give feedback.
All reactions