router-core-code-splitting

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

Updated Dec 21, 2025
One-click install
npx skills add https://github.com/Angael/veles --skill router-core-code-splitting-angael
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core-code-splitting
Source: https://github.com/Angael/veles/tree/main/.agents/skills/router-core-code-splitting
Command: npx skills add https://github.com/Angael/veles --skill router-core-code-splitting-angael

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Route components and loaders can bloat the main JavaScript bundle, slowing initial page loads. This Skill guides correct code splitting in TanStack Router so non-critical route code loads lazily while critical routing logic stays in the main bundle. ## 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 typed hooks like useLoaderData and useSearch without importing the Route object and defeating the split. - Use Case: A dashboard app with heavy chart components on /reports can split that component into its own 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 lazy-loaded correctly.

Frequently Asked Questions about router-core-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 stay in the main bundle.

How to code split TanStack Router routes without the bundler plugin?

Create a .lazy.tsx file alongside the route file and use createLazyFileRoute for the component. The main route file keeps only critical config like the loader, and the lazy file supports component, errorComponent, pendingComponent, and notFoundComponent.

Why is my TanStack Router code splitting not working?

The most common cause is exporting the component function from the route file, which forces it into the main bundle. Another cause is importing the Route object into lazy files instead of using getRouteApi for typed hooks.

Should I code split the loader in TanStack Router?

No, the loader is not split by default because it is already async. Splitting it adds a double async cost: fetching the chunk first, then executing the loader, which delays data fetching.

Can I code split the root route in TanStack Router?

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

How do I override code splitting for a specific route?

Add codeSplitGroupings directly in the route file, for example [['loader', 'component']] to bundle them together. Per-route groupings take precedence over splitBehavior functions and defaultBehavior options.