Nested Route Splitting Strategies
What you'll learn: How to decide the right level of granularity when splitting code in nested route structures—avoiding both bloated parent bundles and over-fragmented child routes.
The Granularity Decision
When you have nested routes (routes inside other routes), you face a critical question: should the parent route bundle include its children, or should each child be split separately?
Think of it like packing for a trip. You could pack one giant suitcase (parent + all children together), many tiny bags (every child split), or a balanced approach (split meaningful sections, keep small items together).
When to Split the Parent
If your parent route component is large or heavy (complex layout, large dependencies), split it from its children. The parent loads first, renders the layout, then children load on-demand:
const ParentLayout = lazy(() => import('./ParentLayout'));
const ChildA = lazy(() => import('./ChildA'));
const ChildB = lazy(() => import('./ChildB'));
When to Keep Children Together
Avoid over-splitting small routes. If ChildA and ChildB are tiny (a few KB each) and users typically visit both, the overhead of multiple network requests outweighs the savings. Bundle them with the parent or together:
// Parent and small children together
const ParentWithChildren = lazy(() => import('./ParentSection'));
The Middle Ground
Split children only when:
- They're substantial in size (20+ KB)
- They're accessed infrequently or independently
- They load heavy third-party libraries unique to that route
Small, frequently-visited child routes should stay bundled to reduce request waterfalls.
Key Takeaway: Split nested routes based on size and access patterns—lazy-load heavy or rarely-used children, but bundle small, frequently-accessed children together to avoid excessive fragmentation and request overhead.