router-core/code-splitting

Explain code-splitting strategies for TanStack Router projects.

6|1|Updated Jun 1, 2025
One-click install
npx skills add https://github.com/rezics/rezics --skill router-core-code-splitting-rezics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core/code-splitting
Source: https://github.com/rezics/rezics/tree/main/.agents/skills/tanstack/router/router-core/code-splitting
Command: npx skills add https://github.com/rezics/rezics --skill router-core-code-splitting-rezics

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Automatic code splitting (autoCodeSplitting) helps keep initial bundles small by moving non-critical route code into lazy-loaded chunks and enabling per-route optimization.

Core Features & Use Cases

  • Automatic code splitting with a bundler plugin to transform route files automatically into split chunks.
  • Manual splitting with .lazy.tsx using createLazyFileRoute and createLazyRoute, plus typed access via getRouteApi in split files.
  • Per-route codeSplitGroupings overrides for fine-grained control and splitBehavior configuration for global strategy.
  • Clear distinction between critical vs non-critical properties to minimize main bundle size and startup time.

Quick Start

Enable automatic code splitting via the bundler plugin, or implement manual splitting with .lazy.tsx as shown.

Frequently Asked Questions about router-core/code-splitting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is code splitting in TanStack Router and why should I use it?

Code splitting in TanStack Router keeps initial bundles small by moving non-critical route code into lazy-loaded chunks. This reduces main bundle size and improves startup time by separating critical and non-critical properties across route files.

How do I set up automatic code splitting with a TanStack Router bundler plugin?

Automatic code splitting uses a bundler plugin to transform route files into split chunks automatically. You enable it via the bundler plugin configuration, which handles the splitting without requiring manual .lazy.tsx file creation.

When should I use manual .lazy.tsx splitting instead of automatic code splitting?

Manual splitting with .lazy.tsx is ideal when you need fine-grained control over specific routes. You use createLazyFileRoute or createLazyRoute for manual chunk creation, while automatic splitting handles broad transformations without per-file modifications.

Can I configure per-route code splitting groupings in TanStack Router?

Yes, you can use per-route codeSplitGroupings overrides for fine-grained control. Global split behavior is managed through defaultBehavior and splitBehavior configurations, allowing you to define the overall code splitting strategy.

Does getRouteApi work inside split lazy-loaded route files?

Yes, getRouteApi provides typed access within split files. You can use it alongside createLazyFileRoute and createLazyRoute in .lazy.tsx files to maintain type safety when accessing route properties in manually split chunks.

What are the limitations of TanStack Router code splitting for bundle optimization?

Code splitting requires distinguishing critical vs non-critical properties to avoid loading unnecessary code. Improper configuration of splitBehavior or grouping overrides may lead to suboptimal chunking, making per-route tuning essential for minimizing startup time.