How do layouts work with the router? #987
Replies: 2 comments 7 replies
-
Hello, answer a bit late, but for a future seekers will write what I found, because documentation lack about layouts mechanics. There are at least 2 options of organising folders to use layouts: Option 1:
Option 2:
So as you see we should intentionally mark which layout we want to use. Inside layouts use |
Beta Was this translation helpful? Give feedback.
-
For anybody else trying to understand how this work, this setup is working for me currently. I can hit the url with the correct layout applied as written in
// routes/campaigns/route.tsx
import { createFileRoute, Outlet } from "@tanstack/react-router";
export const Route = createFileRoute("/campaigns")({
component: CampaignsLayout,
});
export function CampaignsLayout() {
return (
<div className="flex flex-col gap-4 p-4 pt-0 bg-red-500">
<h1>Campaigns Layout</h1>
<Outlet />
</div>
);
} // routes/campaigns/create.tsx
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/campaigns/create")({
component: RouteComponent,
});
function RouteComponent() {
return <div>Hello "/campaigns/create"!</div>;
} |
Beta Was this translation helpful? Give feedback.
-
Hi, I'd like to start by thanking you for building the router - it is great and super nice.
I am trying to understand how router (v1.4.2) + layouts work. If you can help me learn more, it would be great.
I have the following file-system structure:
The code in
./_layout.tsx
:The code in
./dash/_layout.tsx
:This generates the following routeTree.gen.ts.
Should the layouts in
auth
anddash
directories be configured to have their own paths or should they be treated differently?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions