What you described here is basically how Next.js works :)
The blog post mentions the 3 APIs that make this possible:
- getStaticProps (Static Generation): Fetch data at build-time.
- getStaticPaths (Static Generation): Specify dynamic routes to prerender based on data.
- getServerSideProps (Server-Side Rendering): Fetch data on each request.