๐ก Need Help with TanStack Router Layouts
Hey everyone ๐
Iโm working on a React project with TypeScript and TanStack Router, and Iโm a bit stuck with creating two different layouts.
๐ Hereโs the setup I want:
- Main Layout โ Navbar + Footer + <Outlet /> (for public pages like About, Pricing, Contact).
- Dashboard Layout โ A totally different layout (no Navbar/Footer from the root).
It should have a Sidebar (on the left) and a small navbar/header (just for Logo or Settings).
The dashboard pages (like Manage Users, Add Money, etc.) should be displayed on the right side.
The issue:
My main layout works fine with Navbar/Footer.
But when I click the Dashboard link after login, I want the layout to switch to the Dashboard layout.
Basically:
/about, /pricing, /contactโ Use Main Layout
/dashboard/* โ Use Dashboard Layout (completely separate from the root Navbar/Footer).
โ My Question:
Whatโs the best way to structure this in TanStack Router?
How do you usually set up multiple layouts (like __root.tsx for public pages and a separate __layout.tsx for dashboard)?
Thanks in advance ๐
7 Replies
mere-tealโข3w ago
Hi
Where are you from?
equal-aquaOPโข3w ago
Bangladesh
@Come on Cat! and you?
mere-tealโข3w ago
Zagreb, Croatia
equal-aquaOPโข3w ago
Greate, do you have any idea about my post?
mere-tealโข3w ago
Can you show me your project?
equal-aquaOPโข3w ago
correct-apricotโข3w ago
Hello Sumon here is an example that I've set up for one of my projects that works well
