Replies: 1 comment
-
You can already achieve this using something like
This is documented here: https://tanstack.com/router/latest/docs/framework/react/routing/file-based-routing. For what it's worth, I would also prefer nested |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
It would be extremely beneficial to support a nested
__root.tsx
file in Tanstack router. The idea is to allow developers to wrap all components within a specific route segment (e.g. /organizations/) in a common root component. This would let us load necessary data (such as organization details) and delay rendering until that data is available, as well as set up a shared context.Motivation
Currently, there isn’t a straightforward way to define a nested root for routes. As a result, if I want to ensure that no route under /organizations/ renders until the organization has been successfully loaded—and, for instance, guarantee that a hook like useOrganization always returns a valid organization—I need to wrap each individual route manually. This approach increases boilerplate and reduces clarity.
The ability to place a
__root.tsx
file (or similar mechanism) in the file structure would allow:Proposed Implementation
Introduce a convention in the router that automatically detects and uses a nested root file (e.g.
__root.tsx
) within a route directory. When present, the router should:__root.tsx
.Example
Below is an example of what I’d like to achieve using this new feature:
Currently, my workaround for organization-specific routes looks like this:
This workaround is less ideal because it requires manually wrapping each route. By using a nested
__root.tsx
file, all routes under /organizations/ could be automatically wrapped in the desired logic.Expected Behavior
With this feature, the router should:
__root.tsx
(or similarly named file) in a directory.Benefits
Beta Was this translation helpful? Give feedback.
All reactions