#Static export of a single page route

1 messages · Page 1 of 1 (latest)

sturdy oyster
#

How can we export a single static page in Next.js ?

grim belfryBOT
#

Hi @sturdy oyster. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Next.js, you can export a single static page by using the next build command. This command generates an HTML file per route. If you want to export a single page, you need to have a single route in your application.

Here's how you can enable static export:

  1. Change the output mode inside next.config.js:
/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  output: 'export',
 
  // Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
  // trailingSlash: true,
 
  // Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
  // skipTrailingSlashRedirect: true,
 
  // Optional: Change the output directory `out` -> `dist`
  // distDir: 'dist',
}
 
module.exports = nextConfig
  1. Run next build. Next.js will produce an out folder which contains the HTML/CSS/JS assets for your application.

Remember, you can utilize getStaticProps and getStaticPaths to generate an HTML file for each page in your pages directory (or more for dynamic routes).

Please note that Internationalized Routing does not integrate with output: 'export' as it does not leverage the Next.js routing layer. Hybrid Next.js applications that do not use output: 'export' are fully supported.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: