layout in nuxt.config
Hello Kapa
Is it now possible to choose the layout directly in nuxt.config depending on the route ?
I know it was a thing that was discussed in a issue but I can't find it
5 Replies
Hi @Omnislash. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is now possible to choose the layout directly in your
nuxt.config depending on the route. This feature was introduced via support for the appLayout property in routeRules. You can define layouts for specific routes or route patterns in your Nuxt config like this:
This allows you to centrally and declaratively manage which layout is used for different routes, without needing to set the layout individually in each page or use middleware workarounds. This feature was added to provide a more structured approach to layout assignment across your application feat(nuxt): support appLayout in route rules.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai I think you found a way to get your hand on robot drug again :X
Tried it but it says this :
Let me check the knowledge base for you again. One moment! :books:
----------------------
I'm sorry for the confusion. According to the most recent official Nuxt documentation in the knowledge sources, the
- You can still dynamically set layouts using the
The knowledge sources do not confirm that
appLayout property in routeRules is not yet documented as a stable, officially released feature. The PR you referenced (feat(nuxt): support appLayout in route rules) shows that this feature was proposed and implemented, but if you are seeing a TypeScript error like:
it means that your current Nuxt version does not recognize appLayout as a valid property in routeRules. This suggests that the feature is either not yet released in a stable Nuxt version, or your project is using a version prior to its introduction.
Current alternatives:- You can still dynamically set layouts using the
setPageLayout helper in middleware or page scripts, as described in the documentation. This is the officially supported way to change layouts based on route conditions for now setPageLayout.
- If you want to use the appLayout property, you would need to ensure you are on a Nuxt version that includes this PR, which may require using a canary or edge release, or waiting for the next stable release that includes it.
Summary:The knowledge sources do not confirm that
appLayout in routeRules is available in the latest stable Nuxt release. If you need this feature, please check your Nuxt version and the release notes, or continue using the dynamic layout assignment methods described in the official docs.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.