import fetch from 'node-fetch'
const Post = () => {
...
}
export async function getStaticPaths() {
const res = await fetch('https://.../posts')
const posts = await res.json()
const paths = posts.map(post => ({
params: { id: post.id },
}))
return { paths, fallback: false }
}
export async function getStaticProps({ params }) {
...
}
export default Post
function Page({ data }) {
...
}
export async function getServerSideProps({ params }) {
const res = await fetch(`https://.../${params.id}`)
const data = await res.json()
return { props: { data } }
}
export default Page
import Link from "next/link";
const index = () => (
<Link href="/blog/[id]" as="/blog/test-post">
test-post link
</Link>
);
import Router from "next/router";
// query 파라미터의 프로퍼티로는 2가 아니라 "second-post"가 들어감
// push메소드는 첫 번째 인자로 href를 받고 두 번째 인자로 as 마지막 세 번째 인자로 option를 받습니다
Router.push("/blog/[id]", "/blog/second-post?id=2");
import Router from "next/router";
Router.push("/blog/first-post?id=5", null, { shallow: true });