nuxi generate only finds 10 from 100 slug routes when paginated to show only 10
Is my approach bad, paginating links? Should I show all links and use CSS to hide the others instead? Anyways, nuxt can't find the other 90 routes. I've tried stuff like this:
but it only still generates the first 10 routes.
3 Replies
Hi @jonspe. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I can offer some insights and suggestions regarding your issue with
nuxi generate
only finding 10 out of 100 slug routes when paginated.
The problem you're experiencing is likely related to how Nuxt's crawler works during the prerendering process. By default, Nuxt will crawl links on your pages to discover routes for prerendering. If you're only showing 10 links per page due to pagination, the crawler may not be able to discover the other 90 routes.
Here are some approaches you can consider:
1. Use nitro.prerender.routes
:
Instead of using the generate
property, you should use nitro.prerender.routes
in your nuxt.config.ts
file. This is the recommended way to specify additional routes for prerendering in Nuxt 3. Here's how you can modify your configuration:
Make sure getBlogRoutes
is an async function that returns an array of routes.
2. Use prerenderRoutes
:
You can also use the prerenderRoutes
function within your pages to hint additional routes for prerendering. This is especially useful for dynamic routes. Here's an example:
Source: Docs > Getting-started > Prerendering
3. Use the prerender:routes
Nuxt hook:
You can use this hook to add more routes for prerendering before the process starts:
Source: Docs > Getting-started > Prerendering
Regarding your question about showing all links and using CSS to hide others: While this approach might help the crawler discover all routes, it's generally not recommended for performance reasons, especially if you have a large number of posts. It's better to use one of the methods described above to explicitly tell Nuxt about all the routes that need to be prerendered.
Remember, the goal is to inform Nuxt about all the routes that need to be generated, rather than relying solely on the crawler to discover them through links on your pages.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@165887165736157185> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
the third option worked for me, thanks kapa