Created
May 1, 2020 09:30
-
-
Save komkanit/43b4493d307e8c6cd539cbf1e991ca96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function getStaticPaths() { | |
// ตรงนี้สามารถ List Content ทั้งหมดผ่าน API ได้ | |
// และใส่เป็น params | |
return { | |
paths: [ | |
{ | |
params: { | |
title: 'some-content-title', | |
}, | |
}, | |
{ | |
params: { | |
title: 'another-content-title' | |
}, | |
} | |
], | |
fallback: false, | |
} | |
} | |
export async function getStaticProps(context) { | |
// ตรงนี้สามารถดึงข้อมูล content ที่ต้องการผ่าน API ได้ | |
const content = { | |
'some-content-title': { content: 'Hello World' }, | |
'another-content-title': { content: 'This is Content' } | |
} | |
return { | |
props: { | |
title: context.params.title, | |
content: content[context.params.title].content | |
}, | |
} | |
} | |
export default (props) => { | |
return ( | |
<> | |
<h1>{props.title}</h1> | |
<p>{props.content}</p> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment