WIP: app -> pages
This commit is contained in:
38
frontend/pages/[slug]/index.js
Normal file
38
frontend/pages/[slug]/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { notFound } from 'next/navigation'
|
||||
import directus from '~/lib/directus'
|
||||
|
||||
export const getStaticPaths = async () => {
|
||||
const { data: pages } = await directus.items('pages').readByQuery({
|
||||
limit: 1,
|
||||
})
|
||||
|
||||
return {
|
||||
paths: pages.map((p) => ({ params: { slug: p.slug } })),
|
||||
fallback: false, // false or "blocking"
|
||||
}
|
||||
}
|
||||
|
||||
export const getStaticProps = async ({ params }) => {
|
||||
const { slug } = params
|
||||
|
||||
const {
|
||||
data: [page],
|
||||
} = await directus.items('pages').readByQuery({
|
||||
limit: 1,
|
||||
filter: {
|
||||
slug: {
|
||||
_eq: slug,
|
||||
},
|
||||
},
|
||||
})
|
||||
return { props: { page } }
|
||||
}
|
||||
|
||||
export default function Page({ page }) {
|
||||
return (
|
||||
<div>
|
||||
<h1>{page.title}</h1>
|
||||
<div dangerouslySetInnerHTML={{ __html: page.content }}></div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user