Layout for Route
I there I'm new to tanstack router for react and I have the following set up:
I have the following stricture:
/profile
/$organisation
/$organisation/$project
/$organisation/$project/list
/$organisation/$project/edit
I have the "main layout" that I use for all routes so I have a RootRoute with my main layout and the <Outlet /> where the rout specific stuff is rendered.
Everything under /$organisation/$project now has a shared layout and navigation inside the <Outlet /> "slot". What would be the best way to share the navigation and layout for /$organisation/$project, /$organisation/$project/list and /$organisation/$project/edit?
7 Replies
typical-coral•2y ago
Can you elaborate more?
eastern-cyanOP•2y ago
Sure, the RootRoute accepty a component that uses the <Outlet /> as the placeholder for the actual Router Component:
But now in my case everything under /$organisation/$project has a sub-navigation. So the over all Markup should look like this:
So in the end, /$organisation/$project would have the same markup as rootRoute plus the subnav and the main. So what I am looking is something like this:
So the projectRootRoute renders into the rootRoute Outlet, if the URL matches /$organisation/$project.
Do you see what I mean?
typical-coral•2y ago
Do you want the project root route to be nested inside of the root route?
eastern-cyanOP•2y ago
Yes.
typical-coral•2y ago
So something like this
eastern-cyanOP•2y ago
Wait.. what? I dont get it.. Can I use <Outlet /> in the component of a Route? If not, how can I define where the Project stuff will be rendered in Parent layout?
typical-coral•2y ago
Outlet renders the potential children of a route as defined in your route tree
Each route with children should render an outlet