code-splitting

Configures automatic and manual route code splitting for TanStack Router applications.

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill code-splitting-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-splitting
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/tanstack-router-core/code-splitting
Command: npx skills add https://github.com/Albo-Club/albo-os --skill code-splitting-albo-club

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router, @tanstack/router-plugin.

What problem does it solve? Route components in TanStack Router apps ship in the main bundle by default, inflating initial load time. This Skill guides correct code splitting of route components so only critical code loads upfront while non-critical UI loads lazily. ## Core Features & Use Cases - Automatic Code Splitting: Enable autoCodeSplitting in the bundler plugin so route components are split into separate chunks without manual file restructuring. - Manual Splitting: Use .lazy.tsx files with createLazyFileRoute or createLazyRoute when the bundler plugin is unavailable, including virtual routes. - Typed Hooks in Split Files: Use getRouteApi to access useLoaderData, useSearch, and useParams without importing the Route object and defeating the split. - Use Case: A dashboard app with heavy chart components on /reports splits that route's component into a lazy chunk, keeping the initial bundle small while the loader stays in the main bundle. ## Quick Start Enable automatic code splitting in my TanStack Router Vite config and refactor my routes so components are split correctly.

Frequently Asked Questions about code-splitting

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

FAQPage Schema
How do I enable automatic code splitting in TanStack Router?

Set autoCodeSplitting: true in the tanstackRouter Vite plugin options, placing the plugin before the React plugin. Route components are then split into separate chunks automatically, while loaders remain in the main bundle.

How do I use typed route hooks in a lazy-loaded route file?

Use getRouteApi('/path') from @tanstack/react-router to access useLoaderData, useSearch, useParams, and useRouteContext in split files. Importing the Route object directly pulls the route config into the lazy chunk and defeats code splitting.

What is the difference between createLazyFileRoute and createLazyRoute?

createLazyFileRoute is for file-based routing with .lazy.tsx files, while createLazyRoute is for code-based routing combined with the .lazy() method on a route. Both support only component, errorComponent, pendingComponent, and notFoundComponent.

Can I code split the root route in TanStack Router?

No, __root.tsx does not support code splitting because it always renders regardless of the current route. Do not create a __root.lazy.tsx file.

Why should the loader not be code split by default?

Splitting the loader adds a double async cost: the browser must fetch the chunk first, then execute the loader. Since loaders are already async, keeping them in the main bundle avoids an extra network waterfall.

Why is my route component still in the main bundle after enabling code splitting?

Exported component functions are included in the main bundle and bypass code splitting. Define the component without an export keyword so the bundler plugin can move it into a split chunk.