import Layout from'../../components/layout'exportdefaultfunctionPost() {return <Layout>...</Layout>}//prod build time, dev every requestexportasyncfunctiongetStaticPaths() {// Returns an array that looks like this:// [// {// params: {// id: 'ssg-ssr'// }// },// {// params: {// id: 'pre-rendering'// }// }// ]//If fallback is false, then any paths not returned by getStaticPaths will result in a 404 page.return {paths, fallback:false};}exportasyncfunctiongetStaticProps({ params }) {// Fetch necessary data for the blog post using params.id}
pages/posts/[...id].js matches /posts/a, but also /posts/a/b, /posts/a/b/c and so on.
functiongetStaticPaths() {//..return [ { params: {// Statically Generates /posts/a/b/c id: ['a','b','c'] } }//... ]}exportasyncfunctiongetStaticProps({ params }) {// params.id will be like ['a', 'b', 'c']}
Router
If you want to access the Next.js router, you can do so by importing the useRouter hook from next/router. Take a look at our router documentation to learn more.