Overview
This quickstart guide will help you build a complete TanStack Start application with:- File-based routing
- Server-side rendering (SSR)
- Server functions for data fetching
- Type-safe RPC calls
- Streaming with Suspense
Step 1: Create Your Project
Start by creating a new directory and initializing a project:Step 2: Install Dependencies
Install TanStack Start and its dependencies:- React
- Solid
- Vue
Step 3: Configure Vite
Create avite.config.ts file:
- React
- Solid
- Vue
vite.config.ts
Step 4: Configure TypeScript
Create atsconfig.json file:
- React
- Solid
- Vue
tsconfig.json
Step 5: Create a Server Function
Create a server function to fetch data. This code runs only on the server:- React
- Solid
- Vue
src/utils/posts.ts
Server functions are automatically transformed into API endpoints by the Vite plugin. The client-side calls become type-safe RPC requests.
Step 6: Create the Root Route
Create the root route with SSR setup:- React
- Solid
- Vue
src/routes/__root.tsx
Key Components for SSR
HeadContent: Renders meta tags, links, and scripts in the<head>Scripts: Injects necessary client-side scripts for hydrationshellComponent: The outer HTML shell rendered on the server
Step 7: Create Route Pages
Create your route pages with data loading:- React
- Solid
- Vue
src/routes/index.tsx
src/routes/posts.index.tsx
Step 8: Create Router Configuration
Create the router configuration file:- React
- Solid
- Vue
src/router.tsx
Step 9: Generate Route Tree
Generate the route tree file. The TanStack Start plugin will auto-generate this file, but you need to create an initial version:src/routeTree.gen.ts
Step 10: Add Package Scripts
Update yourpackage.json with the necessary scripts:
package.json
Step 11: Run Your Application
Start the development server:http://localhost:5173 (or another port if 5173 is in use).
What’s Happening?
- SSR: Pages are rendered on the server first
- Server Functions: The
fetchPostsfunction runs on the server - Hydration: The client-side JavaScript makes the page interactive
- Type Safety: Full type safety from server to client
Step 12: Test Server Functions
Visithttp://localhost:5173/posts and check your server logs. You should see:
Advanced: Streaming with Suspense
Add streaming support for better perceived performance:- React
- Solid
- Vue
src/routes/posts.deferred.tsx
Build for Production
Build your application for production:.output directory:
.output/public/: Static client assets.output/server/: Server bundle
Next Steps
Congratulations! You’ve built your first TanStack Start application. Here’s what to explore next:Server Functions
Deep dive into server functions, validation, and error handling
SSR & Streaming
Learn about advanced SSR and streaming patterns
API Routes
Create custom API endpoints for external clients
Deployment
Deploy your app to Netlify, Vercel, Cloudflare, and more