Files
next-learn/basics/dynamic-routes-step-1/pages/posts/[id].js
2023-09-06 12:57:56 -05:00

32 lines
564 B
JavaScript

import Layout from '../../components/layout';
import { getAllPostIds, getPostData } from '../../lib/posts';
export default function Post({ postData }) {
return (
<Layout>
{postData.title}
<br />
{postData.id}
<br />
{postData.date}
</Layout>
);
}
export async function getStaticPaths() {
const paths = getAllPostIds();
return {
paths,
fallback: false,
};
}
export async function getStaticProps({ params }) {
const postData = getPostData(params.id);
return {
props: {
postData,
},
};
}