T
TanStack2y ago
continuing-cyan

how do you correctly mix path named routes & layouts?

Amir Ghezelbash
StackBlitz
Router Kitchen Sink File Based Example (forked) - StackBlitz
Run official live example code for Router Kitchen Sink File Based, created by Tanstack on StackBlitz
No description
25 Replies
continuing-cyan
continuing-cyanOP2y ago
btw /aaa/bbb/layout is working
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
I tried this it's not working either 😦
No description
rare-sapphire
rare-sapphire2y ago
Using layout routes, you typically want to drop the routes under the layout in a folder with that name. https://stackblitz.com/edit/tanstack-router-iwxx8v?file=src%2Froutes%2F%24lang%2F%24entityid%2F_app-layout%2Findex.tsx I did this, and it worked.
Sean Cassiere
StackBlitz
Layout routes fix - StackBlitz
Run official live example code for Router Kitchen Sink File Based, created by Tanstack on StackBlitz
No description
continuing-cyan
continuing-cyanOP2y ago
gonna give it a try and let you know how it goes @Sean Cassiere
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
it does not render anything for me in the link you posted @Sean Cassiere
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
this works though
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
Problem is I want to have multiple pages in the $entityId with that should be wrapped by the same layout Basically i'm trying to achieve this: app.com/$lang/$entityId/page1 (...2,3,4 different pages) app.com/en/entiy-example-id/page1 app.com/en/entiy-example-id/page2 app.com/en/entiy-example-id/page3 app.com/en/entiy-example-id/page4 all pages should have the same layout
continuing-cyan
continuing-cyanOP2y ago
I can't do it this way either because $entityId is not the same name as _app-layout
No description
rare-sapphire
rare-sapphire2y ago
Have you tried placing $entityId inside of a folder called _app-layout? Also, why can't app-layout be inside of entityid? Otherwise, how would you get the $entityid to pass into navigation components of _app-layout? Because if your layouts are set up at the $lang directory, then you wouldn't have access to the $entityid params.
rare-sapphire
rare-sapphire2y ago
I've got an example here, you can still have pages within $entity that are not wrapped in _layout. I've trimmed in down to what we are talking about here. https://stackblitz.com/edit/github-npuuth?file=src%2Froutes%2F%24lang%2F%24entity%2F_layout.tsx
Sean Cassiere
StackBlitz
layout routes go brrr - StackBlitz
Run official live example code for Router Basic File Based, created by Tanstack on StackBlitz
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
in your example there is a layout in the url: en-US/12345/layout/ what I need is to be able to have more nested routes for example: en-US/12345/setting en-US/12345/invoices en-US/12345/staff ... this is ruining the entire point of layouts right? they are supposed to not be included in the URL 🤔 @Sean Cassiere also why do you use a .component.tsx? is that something special?
dependent-tan
dependent-tan2y ago
Code Splitting | TanStack Router Docs
Code splitting is a powerful technique for improving the bundle size and load performance of an application. Reduces the amount of code that needs to be loaded on initial page load
rare-sapphire
rare-sapphire2y ago
rare-sapphire
rare-sapphire2y ago
It allows me to not have to define the new FileRoute stuff and creates a virtual route in the routeTree.gen.ts file.
continuing-cyan
continuing-cyanOP2y ago
thanks a million @Sean Cassiere it's working now.
continuing-cyan
continuing-cyanOP2y ago
No description
continuing-cyan
continuing-cyanOP2y ago
just to confirm, making this route.tsx was the key to make it work right?
rare-sapphire
rare-sapphire2y ago
Yup, for whatever reason only with it and its Outlet component did it work. I wish I understood why, but realistically it could unremain touched for the rest of the repos history so 🤷🏼‍♀️
wise-white
wise-white2y ago
I think you could just do an empty object as well instead of adding only the outlet component. Seems to work on my end
continuing-cyan
continuing-cyanOP2y ago
yup it does. thanks

Did you find this page helpful?