angrybeanie-front-end/pages/news/[slug].js
2020-12-06 21:49:37 +11:00

26 lines
No EOL
819 B
JavaScript

import "../../components/main.js"
import Layout from "../../components/main.js"
export async function getServerSideProps(context) {
const slug = context.params.slug
const url = 'http://localhost:8000/api/document/' + slug
console.log(url)
const res = await fetch(url)
const article_obj = await res.json()
const secres = await fetch(`http://localhost:8000/api/sections`)
const secdata = await secres.json()
return {
props: { article_obj, sections: secdata }, // will be passed to the page component as props
}
}
const Article = ({article_obj, sections}) => (
<Layout sections={sections}>
<h1>{article_obj.title}</h1>
<div className="article_body" dangerouslySetInnerHTML={{ __html: article_obj.body }}></div>
</Layout>
)
export default Article