Next.jsと
"next": "^10.0.5",
"typescript": "^4.1.3"
基本的に
getStaticProps
関数を
export const getStaticProps = async () => {
return {
props: {
posts: await getPosts() // 投稿を取得
}
}
}
各投稿ページもgetStaticPaths
, getStaticProps
関数を
export const getStaticPaths: GetStaticPaths = async () => {
return {
fallback: false,
paths: await getPaths() // 記事のパスを取得
}
}
export const getStaticProps: GetStaticProps<Props> = async ({ params }) => {
return {
props: {
post: await getPost(params?.id) // 記事を取得
}
}
}
静的ファイルを
next export
SSGに
next build
next start
すごく
次は