Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional info on this page would be awesome… #504

Open
DavidSabine opened this issue Mar 19, 2025 · 2 comments
Open

Additional info on this page would be awesome… #504

DavidSabine opened this issue Mar 19, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@DavidSabine
Copy link

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:

  1. Do the following configs achieve essentially the same outcome?
  2. Should one be preferred?
  3. 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'],
    }
  }
@DavidSabine DavidSabine added the enhancement New feature or request label Mar 19, 2025
Copy link
Contributor

atinux commented Mar 19, 2025

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? 🙂

@DavidSabine
Copy link
Author

DavidSabine commented Mar 19, 2025

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:

  1. I blended the Nuxt UI Pro Saas, Landing, and Dashboard templates (so awesome!)
  2. and then built a jobs table in the sqlite DB (hosted at Nuxthub).
  3. In the dashboard, I created tools to CRUD the jobs table.
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants