Ignore query params in Nitro prerender
Does anyone know how to ignore query params when using Nitro prerender in Nuxt 3? It crawls every URL, including ones with query params. I want them to be ignored by the crawler.
5 Replies
Hi @Joey. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To ignore query parameters when using Nitro prerender in Nuxt 3, you can configure the
isr
(Incremental Static Regeneration) option in your nuxt.config.ts
file. Here's how you can do it:
By setting allowQuery
to an empty array, you're telling Nitro to ignore all query parameters when caching and prerendering pages Fine-grained ISR config via route rules (https://nitro.unjs.io/deploy/providers/vercel#fine-grained-isr-config-via-route-rules).
This configuration will apply to all routes ("/**"
), but you can also specify it for specific routes if needed.
It's worth noting that this feature is currently available in the nightly channel of Nitro. If you're not using the nightly version, you might need to update to access this functionality.
If you're specifically looking to ignore query parameters during the crawling process, you might also want to consider using the ignore
option in the nitro.prerender
configuration:
This will tell the crawler to ignore any routes that match the specified pattern, including those with query parameters Config > Routing > prerender
(https://nitro.unjs.io/config#prerender).
Remember that these configurations might slightly differ depending on your exact Nuxt and Nitro versions, so always refer to the most up-to-date documentation for your specific setup.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@699655702314221588> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Thanks @kapa.ai, but how do I do this with the ignore property in nitro.prerender on a dynamic route?
Let me check the knowledge base for you again. One moment! :books:
----------------------
To ignore query parameters on a dynamic route using the
ignore
property in nitro.prerender
, you can use a wildcard pattern. Here's how you can configure it in your nuxt.config.ts
file:
In this configuration:
- /your-dynamic-route/**
matches any dynamic route and its nested paths
- ?*
at the end ignores any query parameters
For example, if your dynamic route is /products/[id]
, you could use:
This will ignore query parameters on routes like /products/1?color=red
, /products/2?size=large
, etc.
If you want to ignore query parameters on all routes, you can use:
This configuration tells the Nitro crawler to ignore any route that contains query parameters Config > Routing > prerender
(https://nitro.unjs.io/config#prerender).
Remember that the ignore
array can contain multiple patterns, so you can add more specific rules as needed:
This approach allows you to have fine-grained control over which dynamic routes and query parameters are ignored during prerendering.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@699655702314221588> Kapa.ai is still learning and improving, please let me know how I did by reacting below.