import Layout from '../../components/layout'
export default function Post() {
return <Layout>...</Layout>
}
//prod build time, dev every request
export async function getStaticPaths() {
// 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};
}
export async function getStaticProps({ 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.
function getStaticPaths() {
//..
return [
{
params: {
// Statically Generates /posts/a/b/c
id: ['a', 'b', 'c']
}
}
//...
]
}
export async function getStaticProps({ 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.