import Head from "next/head";
export default function Home() {
return (
<div className="container">
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
</div>)
}
Routes like /post/[id]
Create a [] in the filename to indicate dynamic pages in Next.js
pages/posts/[id].js
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
}