Skip to content

Instantly share code, notes, and snippets.

Last active Sep 18, 2020
What would you like to do?
This code snippet is an example of using getStaticPaths to enable static generation for a React application page with Next.js. This code snippet is from the article originally published on RubyGarage’s blog:
// This function gets called at build time
export async function getStaticPaths() {
// Call an external API endpoint to get posts
const res = await fetch('https://.../posts')
const posts = await res.json()
// Get the paths we want to pre-render based on posts
const paths = => `/posts/${}`)
// We'll pre-render only these paths at build time.
// { fallback: false } means other routes should 404.
return { paths, fallback: false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment