T
TanStack6mo ago
ratty-blush

How to add a _pathlesslayout on the route node

I want make my pathless route a navbar on my root node that i can keep so it doesn't get re-rendered al the time. Is virtual routes the only way to do this?
8 Replies
absent-sapphire
absent-sapphire6mo ago
please add a complete minimal example to showcase what you try to do
other-emerald
other-emerald6mo ago
Why dont you place the navbar directly in the __root.tsx file? otherwise, just use a main layout, like
- __root.tsx
- _MainLayout/
- route.tsx // Layout code, for all routes
- index.tsx // Index page
- // ...other routes
- __root.tsx
- _MainLayout/
- route.tsx // Layout code, for all routes
- index.tsx // Index page
- // ...other routes
or
- __root.tsx
- _MainLayout.tsx // Layout code, with navbar
- _MainLayout/
- index.tsx // Index page
- // ...other routes
- __root.tsx
- _MainLayout.tsx // Layout code, with navbar
- _MainLayout/
- index.tsx // Index page
- // ...other routes
ratty-blush
ratty-blushOP6mo ago
@ferretwithabéret Thanks that first one worked out. Mentally I kept thinking the index.tsx had to be in the same path as the __root.tsx. I didn't want a navbar on every page. just the first index page
other-emerald
other-emerald6mo ago
both of the above are equivalent, they literally do the same thing it is your preference which dictates which one you want to use
ratty-blush
ratty-blushOP6mo ago
got it, appreciate the help question how does re-rendering work with pathless routes does it rerender the whole route and child routes?
absent-sapphire
absent-sapphire6mo ago
no why? router only re-renders routes if something you subscribed to changed. if that does not answer your question please give some example where you are concerned
ratty-blush
ratty-blushOP6mo ago
lets say i have a navbar as a pathless route. I click on a link in the navbar. Is the navbar suppose to rerender with the outlet or just the outlet? I'm using react scan and hmr and it seems everything rerenders when i would think just the outlet changes. Just trying to get a mental model of what renders and what doesn't when something changes or when it goes to a new route.
absent-sapphire
absent-sapphire6mo ago
what does the navbar do? does it subscribe to router state?

Did you find this page helpful?