Automatic Code Splitting
Hello, i would like to know if automatic code splitting works only with files named route.tsx or it's available for all routable file in our routes directory.
this part confused me a little on the doc. I would like to know if posts/$postId.tsx benefit automatic code spliting.
Thanks a lot !
8 Replies
metropolitan-bronze•5mo ago
All routes are code-split automatically
fascinating-indigoOP•5mo ago
Thanks ! they is a way to check that in dev tool ?
metropolitan-bronze•5mo ago
doubt, but you can run a build and analyze the bundles
fascinating-indigoOP•5mo ago
okay thanks a lot, really
metropolitan-bronze•5mo ago
also, route.tsx is just a way of exposing a route on a path.
The different between
route.tsx
and index.tsx
is that route.tsx
will allow nesting, aka it will be the layout of a child route. index.tsx
will always be a leaf route.
All other files, for example if you have some-route.tsx
it will work like some-route/route.tsx
by default
so, for example
will generate 2 paths
/some-route
and /some-route/something-else
.
If you go to /some-route/something-else
the components for both some-route.tsx
and some-route.something-else.tsx
will both be visible (if you have an <Outlet />
in some-route.tsx
)fascinating-indigoOP•5mo ago
ohhh that's why my pathless routing didn't works and when i renamed it to route.tsx and put the outlet inside everything worked perfectly
metropolitan-bronze•5mo ago
if you have no outlet, both will only render the component of
some-route.tsx
even though both routes match on the /some-route/something-else
path
if you want them as separate non-nesting routes, you do some-route.index.tsx
or some-route/index.tsx
These behaviours are what was hard for me to understand when I started using tanstack router too, hence why I always mention them when answering questions about route.tsx/index.tsx to othersfascinating-indigoOP•5mo ago
yeah it's a little confusing
i understand know
thank you man