Layout in Wasp Client
How are layouts handled on the client side in wasp, do you have the root layout system like next Js or do you subscribe individual pages to layouts. I honestly prefer the latter.
2 Replies
Hi @Julius_Java#00. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Wasp, layouts are handled differently than in Next.js. Wasp provides two main approaches for implementing layouts:
1. Root Component - This is a top-level wrapper for your entire application, similar to a global layout.
2. Individual Layout Components - You can create custom layout components and apply them to individual pages.
Root Component Approach
Wasp allows you to define a "wrapper" component for your entire React app using the
rootComponent
field in the client
configuration:
This Root component receives children
props and must render them:
This approach is documented in the Client Config documentation.
Individual Layout Components
For more granular control, you can create custom layout components and use them in your individual pages. For example, in authentication pages:
This approach is shown in the Auth documentation.
Future Improvements
It's worth noting that there are open GitHub issues discussing improvements to Wasp's layout system, including support for nested routes and more sophisticated layout management. These features are being considered but are not yet implemented.
Based on your preference for subscribing individual pages to layouts, the second approach would be more aligned with your preference, as it gives you more control over which layout is applied to each page.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Julius_Java#00, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?There is just root layout that you can declare, but then you wrap your code where you need with another Layout components