core
core copied to clipboard
Additional info on this page would be awesome…
Describe the solution you'd like
On the 3.pre-rendering.md doc, it could be helpful to explain why a person would (or would not) configure nitro and nuxt.
For example:
- Do the following configs achieve essentially the same outcome?
- Should one be preferred?
- Does the universe implode if both are used?
routeRules: {
'/': { prerender: true }
}
nitro: {
prerender: {
routes: ['/'],
}
}
And what if configs contradict each other — which takes precedent? Does a redneck hiccup each time I run nuxt build with the following?
routeRules: {
'/articles': { prerender: true },
'/songs': { prerender: false },
}
nitro: {
prerender: {
ignore: ['/articles'],
routes: ['/songs'],
}
}
This is the problem of having many options to choose from 😆
The first two examples are exactly the same, it is syntax sugar and also that routeRules support much more than only pre-rendering, this is why I rather document and advice it.
Regarding the second exemple, I would love to know the final result, happy to share with me? 🙂
Thanks for joining the thread.
I've learned more since posting the original question yesterday. I'll share info HERE for future me and anyone else who will stumble on this thread someday.
Here's my actual use case:
- I blended the Nuxt UI Pro Saas, Landing, and Dashboard templates (so awesome!)
- and then built a
jobstable in the sqlite DB (hosted at Nuxthub). - In the dashboard, I created tools to CRUD the
jobstable. - And at
/jobs, I created pages to display the data (via/api/jobs) at runtime. (I considered how I might do this as a custom source via @nuxt/content but took the path of creating a 'list page & details page' concept.
It's online at https://employment.link/jobs/ (fyi)
This is currently in my nuxt.config.ts
nitro: {
prerender: {
ignore: ['/jobs'],
routes: ['/', '/docs/help-centre', '/blog'],
crawlLinks: true,
},
},
routeRules: {
'/api/**': {
cors: true,
},
'/': { prerender: true },
'/blog': { prerender: true },
'/docs': { redirect: '/docs/help-centre', prerender: false },
'/pricing': { prerender: true },
},
Notice the /docs problem.
This was interesting.
The Nuxt Ui Pro Docs template redirect /docs requests to /docs/help-centre then populates the pages with *.yml content. Since the /docs index page is essentially empty, there’s no need to pre-render it as an empty HTML document. But we should want the docs pages pre-rendered in the build.
To achieve this, I used the Nitro pre-render routes to bypass the docs index page and directly access the /docs/help-centre page, then crawl the links from there. This works. I see a dist/docs/help-centre subfolder in the build and the other pages automatically crawled by Nitro.
Notice the other Nitro problem
My /jobs pages are not captured by nuxt build — but Nitro chokes on the path when crawlLinks causes Nitro to hit that path.
Thus:
ignore: ['/jobs']
Both of these are examples of how nuxt and nitro prerender operations can be used in a complementary way.