logo

该视频仅会员有权观看

立即开通课程「Next.js 前端应用开发实践」权限。

¥
199
/ 年

静态化动态路由(generateStaticParams)

  • Next.js applications can staticize pages using dynamic routing, allowing content to be fetched based on a URL parameter.
  • During the build process, Next.js can generate static content pages by using a custom generateStaticProps function that returns an array with the required ID properties.
  • The pages generated have a route parameter corresponding to the content's ID via a template literal in the function.
  • After running the build command (npm run build), Next.js will display content titles in the terminal indicating it's rendering static content pages.
  • These static HTML files for the content pages can be found in the dr next server app post directory.
  • Starting the application with (npm run start) and opening a content page from the list now shows a static content page with no rendering in the server-side console, demonstrating that the page is pre-rendered.