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: https://rubygarage.org/blog/how-to-integrate-ssr-for-react-app
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
// 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.map((post) => `/posts/${post.id}`) | |
// 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