Skip to content

Commit 012b2ea

Browse files
onmaxatinux
andauthored
docs: prerender dynamic pages using modules (#300)
Co-authored-by: Sébastien Chopin <seb@nuxtlabs.com>
1 parent 149d28f commit 012b2ea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/content/1.docs/3.recipes/3.pre-rendering.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ export default defineNuxtConfig({
8686
})
8787
```
8888

89+
### Using a Nuxt Module
90+
91+
You can also use a [local Nuxt module](https://nuxt.com/docs/guide/going-further/modules) to pre-render dynamic pages, which is particularly useful if you don't have a single root page (such as `/blog`) but still need to pre-render specific routes, such as `/page-1`, `/parent/page-2`, and so on.
92+
93+
```ts [modules/prerender-routes.ts]
94+
import { defineNuxtModule, addPrerenderRoutes } from '@nuxt/kit'
95+
96+
export default defineNuxtModule({
97+
meta: {
98+
name: 'nuxt-prerender-routes',
99+
},
100+
async setup() {
101+
const pages = await getDynamicPages()
102+
addPrerenderRoutes(pages)
103+
},
104+
})
105+
106+
async function getDynamicPages(): string[] {
107+
// Replace this function with the logic for retrieving the slugs for your pages.
108+
return ['/page-1', '/parent/page-2']
109+
}
110+
```
111+
89112
## Pre-render All Pages
90113

91114
To have the same behavior as [`nuxt generate`](https://nuxt.com/docs/api/commands/generate) while keeping the server part, you can pre-render all pages by configuring the `nitro.prerender` option in the `nuxt.config.ts`:

0 commit comments

Comments
 (0)