TanStack Start
TanStack Start is a full-stack Web framework based on TanStack Router, now supporting React and Solid. Combining Vite build capacity, it provides type-safe routes, Server-side rendering (SSR), streaming, Server Functions, and other features, enabling you to build high-performance full-stack Web applications.
Note:
Pages now supports TanStack Start 1.0+ with full-stack deployment capabilities.
Core Features
Type-safe routing: Fully support TypeScript with type inference for routing parameters and data loading.
Full-stack framework: Support server-side rendering, API routing, and integration of front-end and back-end development.
File-based routing: Based on the file system route agreement, automatically generate a route tree.
Data loading: Built-in loader mechanism supports server-side data retrieval.
Streaming rendering: Supports React 18 Suspense and streaming SSR.
Getting Started
You can deploy TanStack Start projects on EdgeOne Pages in the following ways:
Import a TanStack Start project from a Git repository
Select the TanStack Start template from the Pages template library
Use the
@edgeone/tanstack-start framework adapter to deploy a local projectLearn about TanStack Start performance on Pages deploy, and click the sample template below:
Pages Support for TanStack Start
TanStack Start Feature | System Support |
Server-Side Rendering (SSR) | ✅ |
Static Site Generation (SSG) | ✅ |
Single Page Application (SPA) | ✅ |
Route Loaders | ✅ |
Server Functions | ✅ |
File-based Routing | ✅ |
Streaming | ✅ |
Deploying a TanStack Start Project on Pages
@edgeone/tanstack-start is a Vite plug-in designed for the Pages platform, automatically building TanStack Start applications into Pages deployment products. Combined with Pages scaffolding, it enables quick deployment of TanStack Start projects.To deploy a TanStack Start project to Pages, follow the steps below.
1. Installing an Adapter
npm install @edgeone/tanstack-start
2. Configure Vite
In
vite.config.ts, introduce and use @edgeone/tanstack-start:import { defineConfig } from "vite";import { tanstackStart } from "@tanstack/react-start/plugin/vite";import viteReact from "@vitejs/plugin-react";import edgeoneAdapter from "@edgeone/tanstack-start";export default defineConfig({plugins: [tanstackStart(),viteReact(),edgeoneAdapter(), // Add the Edgeone adapter],});
3. Deploy Project
Git Connection Deployment
After seamless integration of the adapter, commit the project to GitHub or GitLab, and use Git connection deployment.
CLI Deployment
Install the scaffolding tool for Pages (see EdgeOne CLI), then use the command to deploy once configured:
edgeone pages deploy
Note:
The current adapter does not support simultaneous use with the Nitro plug-in. If you need to use Nitro, please wait for the official EdgeOne Pages preset to be released.
Server-Side Rendering (SSR)
TanStack Start enables SSR by default. Use the
loader function to retrieve data from the server.// app/routes/posts.$postId.tsximport { createFileRoute } from "@tanstack/react-router";export const Route = createFileRoute("/posts/$postId")({loader: async ({ params }) => {const post = await fetchPost(params.postId);return { post };},component: PostComponent,});function PostComponent() {const { post } = Route.useLoaderData();return (<article><h1>{post.title}</h1><div>{post.content}</div></article>);}
Static Site Generation (SSG)
Support pre-rendering static pages during build.
// app/routes/about.tsximport { createFileRoute } from "@tanstack/react-router";export const Route = createFileRoute("/about")({// Static data pre-rendered at build timeloader: () => ({title: "About Us",description: "Learn more about our company.",}),component: AboutComponent,});function AboutComponent() {const data = Route.useLoaderData();return (<div><h1>{data.title}</h1><p>{data.description}</p></div>);}
Server Functions
TanStack Start supports server functions, which can run on the server for sensitive operations.
// app/routes/api.tsimport { createServerFn } from "@tanstack/react-start/server";export const getServerTime = createServerFn().handler(async () => {return new Date().toISOString();});export const createUser = createServerFn().validator((data: { name: string; email: string }) => data).handler(async ({ data }) => {// Execute a database operation on the serverconst user = await db.users.create(data);return user;});
Streaming Rendering
Support streaming rendering through React 18's Suspense, gradually transmitting page content.
import { Suspense } from "react";import { createFileRoute, Await } from "@tanstack/react-router";export const Route = createFileRoute("/dashboard")({// Return Promises without awaitingloader: () => ({posts: fetchPosts(),stats: fetchStats(),}),component: DashboardComponent,});function DashboardComponent() {const { posts, stats } = Route.useLoaderData();return (<div><Suspense fallback={<p> Loading posts... </p>}><Await promise={posts}>{(data) => <PostList posts={data} />}</Await></Suspense><Suspense fallback={<p> Loading stats... </p>}><Await promise={stats}>{(data) => <StatsPanel stats={data} />}</Await></Suspense></div>);}
