N
Nuxt5d ago
valerio

Is it possible to prerender all pages in ~/pages?

Is it possible to prerender all pages in ~/pages without having to specify them directly in the nuxt.config.ts file?
2 Replies
kapa.ai
kapa.ai5d ago
Hi @valerio. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to prerender all pages in the ~/pages directory without specifying each one directly in the nuxt.config.ts file. You can achieve this by using the nuxi generate command, which leverages the Nitro crawler to automatically discover and prerender pages. When you run nuxi generate, the Nitro crawler will: 1. Load the HTML of your application's root route (/), any non-dynamic pages in your ~/pages directory, and any other routes specified in the nitro.prerender.routes array. 2. Save the HTML and payload.json to the ~/.output/public/ directory to be served statically. 3. Find all anchor tags (<a href="...">) in the HTML to navigate to other routes. 4. Repeat the process for each anchor tag found until there are no more anchor tags to crawl. This process ensures that all linked pages are prerendered automatically. However, it's important to note that pages not linked from a discoverable page won't be pre-rendered automatically. You can read more about this process in the Nuxt prerendering documentation. If you want to ensure that specific routes are prerendered, you can still manually specify them in the nuxt.config.ts file using the nitro.prerender.routes option:
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ["/user/1", "/user/2"],
ignore: ["/dynamic"],
},
},
});
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ["/user/1", "/user/2"],
ignore: ["/dynamic"],
},
},
});
For more information, you can refer to the Nuxt prerendering documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5d ago
<@612831566565212160> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?