N
Nuxt18h ago
DANANZ M1

Layered Nuxt apps: How to remove routeRules defined in a base layer from an extending layer?

Okay, I'm working with layered Nuxt applications. I have app1 which is the base layer, and app2 which extends app1. In app1, I've configured several routeRules in the nuxt.config.ts. Now, in app2, I want to effectively remove or override some of the routeRules that were set in app1. How can I achieve this? For example, if app1 has a routeRules entry like this:
// app1/nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/some-path': { redirect: '/new-path' },
// ... other rules
}
})
// app1/nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/some-path': { redirect: '/new-path' },
// ... other rules
}
})
In app2, I want to somehow disable or remove the /some-path redirect rule that was defined in app1. Crucially, I don't want to have to explicitly list each path I want to remove in app2 (like telling Nuxt hooks to ignore '/some-path'). I'm looking for a more automatic way for app2 to override or discard specific routeRules from app1 without manual intervention for each rule I want to discard. What's the recommended approach for this in a layered setup?
2 Replies
kapa.ai
kapa.ai18h ago
Hi @DANANZ M1. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but the knowledge sources do not provide a built-in or automatic way to remove or override specific routeRules from a base layer in an extending Nuxt layer without explicitly listing the paths you want to change. Here's what is documented: - The merging of configuration (including routeRules) in layered Nuxt apps is handled by unjs/defu, which merges objects deeply. This means that if you define a routeRule for the same path in the extending layer, it will override the rule from the base layer for that path. However, there is no documented way to "remove" a rule entirely—if you want to disable a rule, you would need to override it with an empty or neutral rule in the extending layer, such as setting it to {} or a no-op config. There is no mention of a special value (like false or null) that would cause a rule to be deleted or ignored during the merge process Going Deeper: Layers. - The only documented way to customize or extend routeRules programmatically is via hooks or the extendRouteRules API, but these approaches still require you to specify which routes you want to modify or remove extendRouteRules API. - There is no mention in the documentation of a configuration or pattern that allows you to automatically "discard" or "unset" inherited routeRules from a base layer without specifying the affected paths. Summary:
You can override a specific routeRule by redefining it in the extending layer's nuxt.config.ts, but you cannot automatically remove or unset inherited routeRules without specifying the path. If you want to "remove" a rule, you must explicitly override it for each path you want to change. If you need more advanced merging or removal logic, you would need to implement custom logic using Nuxt hooks (such as manipulating the merged config in a module or hook), but this is not provided out-of-the-box and would still require you to identify which rules to remove. If future versions of Nuxt introduce a more automatic or declarative way to do this, it is not documented in the current knowledge sources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai18h ago
<@970727290772283392> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?