cache
When using nuxt routerules and swr, is it possible to ingnore the query parameters when caching the page so that all pages with same path but different query parameters use the same cache?
allowQuery option in the route rules.allowQuery option to control which query parameters are considered for caching:allowQuery is set to an empty array, query values are not considered for caching.allowQuery is undefined, each unique query value is cached independently.allowQuery to an empty array. Here's an example of how you can configure this in your nuxt.config.ts:/products/ path will use the same cache, regardless of their query parameters.isr (Incremental Static Regeneration) option, which is specific to certain deployment platforms like Vercel, the swr option works similarly for Nuxt's built-in caching mechanism.isr enables Incremental Static Regeneration for the specified route.allowQuery: [] sets an empty array, which means query parameters will be ignored for caching purposes.nuxt.config.ts:swr: true enables Stale-While-Revalidate caching for the specified route.cache: { allowQuery: [] } sets an empty array for allowQuery, which means query parameters will be ignored for caching purposes.swr option in route rules is actually a shortcut for setting up cache with SWR behavior. As mentioned in the Nitro route rules documentation (https://nitro.unjs.io/guide/routing#route-rules), swr: true|number is a shortcut for cache: { swr: true, maxAge: number }.allowQueryallowQueryallowQueryallowQueryallowQueryallowQuery/products/isrisrswrswrallowQuery: []swr: truecache: { allowQuery: [] }swr: true|numbercache: { swr: true, maxAge: number }export default defineNuxtConfig({
routeRules: {
'/products/**': {
isr: {
swr: true,
allowQuery: [],
},
},
},
})export default defineNuxtConfig({
routeRules: {
'/products/**': {
isr: {
allowQuery: [],
},
},
},
})export default defineNuxtConfig({
routeRules: {
'/products/**': {
swr: true,
cache: {
allowQuery: []
}
}
}
})