router-core/code-splitting

Split TanStack Router route code into critical and non-critical chunks.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/guillempuche/engranatge --skill router-core-code-splitting-guillempuche
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core/code-splitting
Source: https://github.com/guillempuche/engranatge/tree/main/docs/repos/tanstack-router/packages/router-core/skills/router-core/code-splitting
Command: npx skills add https://github.com/guillempuche/engranatge --skill router-core-code-splitting-guillempuche

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers struggle with large bundle sizes and slow load times because route code, including components and hooks, is bundled together without separation of critical and non‑critical parts.

Core Features & Use Cases

  • Automatic code splitting: Enable autoCodeSplitting in the Vite plugin to let the bundler automatically separate critical and non‑critical route code.
  • Manual .lazy.tsx files: Create .lazy.tsx files for routes that need explicit lazy loading of components, error, pending, or not‑found UI.
  • Typed hook access: Use getRouteApi to safely access route hooks from split files without importing the route definition.
  • Per‑route overrides: Define codeSplitGroupings or splitBehavior to customize how each route is chunked.
  • Virtual routes: Omit empty critical files and let the router generate virtual routes automatically.

Quick Start

Enable auto code splitting by setting autoCodeSplitting to true in the TanStack Router Vite plugin configuration.

Frequently Asked Questions about router-core/code-splitting

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

FAQPage Schema
What is autoCodeSplitting in Vite for TanStack Router?

Reduce bundle size by enabling autoCodeSplitting in the TanStack Router Vite plugin to automatically separate critical and non-critical route code. Alternatively, create .lazy.tsx files to explicitly lazy load components and hooks.

How do I manually lazy load route components using .lazy.tsx files?

AutoCodeSplitting is a Vite plugin feature that automatically splits route code into critical and non-critical chunks. By setting autoCodeSplitting to true, the bundler separates components and hooks without requiring manual file creation, optimizing web application load performance.

How do I access typed hooks from split route files without importing route definitions?

Create .lazy.tsx files for routes that need explicit lazy loading of components, error, pending, or not-found UI. This manual approach allows precise control over when non-critical route code is loaded, complementing or replacing the automatic Vite plugin configuration.

Can I customize code splitting behavior for individual TanStack routes?

Use getRouteApi to safely access typed route hooks from split .lazy.tsx files. This allows you to use hooks without importing the main route definition file, keeping critical and non-critical code separated for better bundle size optimization.

Do I need to create empty critical files for virtual routes in TanStack Router?

Yes, define codeSplitGroupings or splitBehavior to customize how each route is chunked. These per-route overrides let you specify exactly how critical and non-critical code is grouped, providing granular control over bundle splitting.

Do I need to create empty critical files for virtual routes in TanStack Router?

No, you can omit empty critical files and let the router generate virtual routes automatically. This simplifies code splitting setup by removing the need for placeholder files when routes only contain non-critical, lazy-loaded code.