diff --git a/.github/labeler.yml b/.github/labeler.yml
index 16ac3b06ef..fe89bd8c8d 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -14,26 +14,12 @@
- 'packages/react-router-with-query/**/*'
'package: react-start':
- 'packages/react-start/**/*'
-'package: start-api-routes':
- - 'packages/start-api-routes/**/*'
'package: react-start-client':
- 'packages/react-start-client/**/*'
-'package: react-start-config':
- - 'packages/react-start-config/**/*'
'package: react-start-plugin':
- 'packages/react-start-plugin/**/*'
-'package: react-start-router-manifest':
- - 'packages/react-start-router-manifest/**/*'
'package: react-start-server':
- 'packages/react-start-server/**/*'
-'package: start-server-functions-client':
- - 'packages/start-server-functions-client/**/*'
-'package: start-server-functions-fetcher':
- - 'packages/start-server-functions-fetcher/**/*'
-'package: start-server-functions-handler':
- - 'packages/start-server-functions-handler/**/*'
-'package: start-server-functions-ssr':
- - 'packages/start-server-functions-ssr/**/*'
'package: router-cli':
- 'packages/router-cli/**/*'
'package: router-core':
@@ -60,18 +46,20 @@
- 'packages/solid-start/**/*'
'package: solid-start-client':
- 'packages/solid-start-client/**/*'
-'package: solid-start-config':
- - 'packages/solid-start-config/**/*'
'package: solid-start-plugin':
- 'packages/solid-start-plugin/**/*'
-'package: solid-start-router-manifest':
- - 'packages/solid-start-router-manifest/**/*'
'package: solid-start-server':
- 'packages/solid-start-server/**/*'
-'package: start':
- - 'packages/start/**/*'
-'package: start-config':
- - 'packages/start-config/**/*'
+'package: start-client-core':
+ - 'packages/start-client-core/**/*'
+'package: start-plugin-core':
+ - 'packages/start-plugin-core/**/*'
+'package: start-server-core':
+ - 'packages/start-server-core/**/*'
+'package: start-server-functions-client':
+ - 'packages/start-server-functions-client/**/*'
+'package: start-server-functions-fetcher':
+ - 'packages/start-server-functions-fetcher/**/*'
'package: start-server-functions-server':
- 'packages/start-server-functions-server/**/*'
'package: valibot-adapter':
diff --git a/.gitignore b/.gitignore
index 5cc3e94113..1db161db9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,20 +60,18 @@ nx-cloud.env
gpt/db.json
-app.config.timestamp-*
+vite.config.timestamp-*
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
-app.config.js.timestamp-*
-app.config.ts.timestamp-*
-app.config.timestamp_*
+vite.config.timestamp_*
vite.config.js.timestamp_*
vite.config.ts.timestamp_*
-app.config.js.timestamp_*
-app.config.ts.timestamp_*
+
.idea
*.vitest-temp.json
# Handling VSCode settings
/.vscode/
-!/examples/react/**/.vscode/settings.json
\ No newline at end of file
+!/examples/react/**/.vscode/settings.json
+**/.tanstack-start/build
\ No newline at end of file
diff --git a/.prettierignore b/.prettierignore
index d285f8937d..25c93015ed 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -7,7 +7,6 @@
pnpm-lock.yaml
**/snapshots
**/.vercel
-**/.vinxi
**/.output
**/node_modules
node_modules
diff --git a/README.md b/README.md
index 4dc5f701b1..7aa0f3d0d4 100644
--- a/README.md
+++ b/README.md
@@ -87,4 +87,4 @@ Enjoy this library? Try the entire [TanStack](https://tanstack.com)! [React Quer
To run example React projects with Tanstack Router, see [CONTRIBUTING.md](./CONTRIBUTING.md)
-
+
diff --git a/docs/router/api/file-based-routing.md b/docs/router/api/file-based-routing.md
index 0e165665c0..777d9f3116 100644
--- a/docs/router/api/file-based-routing.md
+++ b/docs/router/api/file-based-routing.md
@@ -132,19 +132,6 @@ By default, this value is set to `false`.
> [!TIP]
> You should ignore the path of your generated route tree file from your linter and formatter to avoid conflicts.
-### `apiBase`
-
-As a framework, [TanStack Start](/start) supports the concept of API routes. This option configures the base path for API routes.
-
-By default, this value is set to `/api`.
-
-This means that all API routes will be prefixed with `/api`.
-
-This configuration value is only useful if you are using TanStack Start.
-
-> [!IMPORTANT]
-> This default value may conflict with your own project's routing if you planned on having a normal route with the same base path. You can change this value to avoid conflicts.
-
### `autoCodeSplitting`
This feature is only available is you are using the TanStack Router Bundler Plugin.
diff --git a/docs/router/eslint/create-route-property-order.md b/docs/router/eslint/create-route-property-order.md
index 3ce5102013..c0fee218d2 100644
--- a/docs/router/eslint/create-route-property-order.md
+++ b/docs/router/eslint/create-route-property-order.md
@@ -29,7 +29,7 @@ Examples of **incorrect** code for this rule:
/* eslint "@tanstack/router/create-route-property-order": "warn" */
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/foo/bar/$id')({
+export const Route = createFileRoute({
loader: async ({context}) => {
await context.queryClient.ensureQueryData(getQueryOptions(context.hello)),
},
@@ -43,7 +43,7 @@ Examples of **correct** code for this rule:
/* eslint "@tanstack/router/create-route-property-order": "warn" */
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/foo/bar/$id')({
+export const Route = createFileRoute({
beforeLoad: () => ({hello: 'world'}),
loader: async ({context}) => {
await context.queryClient.ensureQueryData(getQueryOptions(context.hello)),
diff --git a/docs/router/framework/react/api/router/createFileRouteFunction.md b/docs/router/framework/react/api/router/createFileRouteFunction.md
index 945e713075..0986d6ccff 100644
--- a/docs/router/framework/react/api/router/createFileRouteFunction.md
+++ b/docs/router/framework/react/api/router/createFileRouteFunction.md
@@ -26,7 +26,7 @@ A new function that accepts a single argument of type [`RouteOptions`](./RouteOp
```tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/')({
+export const Route = createFileRoute({
loader: () => {
return 'Hello World'
},
diff --git a/docs/router/framework/react/api/router/retainSearchParamsFunction.md b/docs/router/framework/react/api/router/retainSearchParamsFunction.md
index 97e411b29c..d4bc185203 100644
--- a/docs/router/framework/react/api/router/retainSearchParamsFunction.md
+++ b/docs/router/framework/react/api/router/retainSearchParamsFunction.md
@@ -39,7 +39,7 @@ const searchSchema = z.object({
two: z.string().optional(),
})
-export const Route = createFileRoute('/hello')({
+export const Route = createFileRoute({
validateSearch: zodValidator(searchSchema),
search: {
middlewares: [retainSearchParams(true)],
diff --git a/docs/router/framework/react/api/router/stripSearchParamsFunction.md b/docs/router/framework/react/api/router/stripSearchParamsFunction.md
index 05b9b02e7f..439a1796d2 100644
--- a/docs/router/framework/react/api/router/stripSearchParamsFunction.md
+++ b/docs/router/framework/react/api/router/stripSearchParamsFunction.md
@@ -30,7 +30,7 @@ const searchSchema = z.object({
two: z.string().default(defaultValues.two),
})
-export const Route = createFileRoute('/hello')({
+export const Route = createFileRoute({
validateSearch: zodValidator(searchSchema),
search: {
// strip default values
@@ -68,7 +68,7 @@ const searchSchema = z.object({
two: z.string().default('xyz'),
})
-export const Route = createFileRoute('/hello')({
+export const Route = createFileRoute({
validateSearch: zodValidator(searchSchema),
search: {
// remove all search params
diff --git a/docs/router/framework/react/decisions-on-dx.md b/docs/router/framework/react/decisions-on-dx.md
index 405db4c6eb..a38716f624 100644
--- a/docs/router/framework/react/decisions-on-dx.md
+++ b/docs/router/framework/react/decisions-on-dx.md
@@ -225,7 +225,7 @@ Let's take a look at how the route configuration for the previous example would
// src/routes/posts/index.ts
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/')({
+export const Route = createFileRoute({
component: () => 'Posts index component goes here!!!',
})
```
diff --git a/docs/router/framework/react/guide/code-splitting.md b/docs/router/framework/react/guide/code-splitting.md
index e2646e402c..e57c7d7fe0 100644
--- a/docs/router/framework/react/guide/code-splitting.md
+++ b/docs/router/framework/react/guide/code-splitting.md
@@ -81,11 +81,11 @@ To enable automatic code-splitting, you just need to add the following to the co
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
export default defineConfig({
plugins: [
- TanStackRouterVite({
+ tanstackRouter({
// ...
autoCodeSplitting: true,
}),
diff --git a/docs/router/framework/react/guide/external-data-loading.md b/docs/router/framework/react/guide/external-data-loading.md
index e2d0e1eb53..2b1ebf78f1 100644
--- a/docs/router/framework/react/guide/external-data-loading.md
+++ b/docs/router/framework/react/guide/external-data-loading.md
@@ -48,7 +48,7 @@ Here is a naive illustration (don't do this) of using a Route's `loader` option
// src/routes/posts.tsx
let postsCache = []
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
loader: async () => {
postsCache = await fetchPosts()
},
@@ -80,7 +80,7 @@ const postsQueryOptions = queryOptions({
queryFn: () => fetchPosts(),
})
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
// Use the `loader` option to ensure that the data is loaded
loader: () => queryClient.ensureQueryData(postsQueryOptions),
component: () => {
@@ -105,7 +105,7 @@ export const Route = createFileRoute('/posts')({
When an error occurs while using `suspense` with `Tanstack Query`, you'll need to let queries know that you want to try again when re-rendering. This can be done by using the `reset` function provided by the `useQueryErrorResetBoundary` hook. We can invoke this function in an effect as soon as the error component mounts. This will make sure that the query is reset and will try to fetch data again when the route component is rendered again. This will also cover cases where users navigate away from our route instead of clicking the `retry` button.
```tsx
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
loader: () => queryClient.ensureQueryData(postsQueryOptions),
errorComponent: ({ error, reset }) => {
const router = useRouter()
diff --git a/docs/router/framework/react/guide/router-context.md b/docs/router/framework/react/guide/router-context.md
index 561b1e2f00..f54e7a7b23 100644
--- a/docs/router/framework/react/guide/router-context.md
+++ b/docs/router/framework/react/guide/router-context.md
@@ -92,7 +92,7 @@ Once you have defined the router context type, you can use it in your route defi
```tsx
// src/routes/todos.tsx
-export const Route = createFileRoute('/todos')({
+export const Route = createFileRoute({
component: Todos,
loader: ({ context }) => fetchTodosByUserId(context.user.id),
})
@@ -122,7 +122,7 @@ Then, in your route:
```tsx
// src/routes/todos.tsx
-export const Route = createFileRoute('/todos')({
+export const Route = createFileRoute({
component: Todos,
loader: ({ context }) => context.fetchTodosByUserId(context.userId),
})
@@ -158,7 +158,7 @@ Then, in your route:
```tsx
// src/routes/todos.tsx
-export const Route = createFileRoute('/todos')({
+export const Route = createFileRoute({
component: Todos,
loader: async ({ context }) => {
await context.queryClient.ensureQueryData({
@@ -234,7 +234,7 @@ So, now in our route's `loader` function, we can access the `networkStrength` ho
```tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
component: Posts,
loader: ({ context }) => {
if (context.networkStrength === 'STRONG') {
@@ -282,7 +282,7 @@ const router = createRouter({
```tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/todos')({
+export const Route = createFileRoute({
component: Todos,
beforeLoad: () => {
return {
diff --git a/docs/router/framework/react/guide/tanstack-start.md b/docs/router/framework/react/guide/tanstack-start.md
index 9704d721c4..a56a204e28 100644
--- a/docs/router/framework/react/guide/tanstack-start.md
+++ b/docs/router/framework/react/guide/tanstack-start.md
@@ -47,15 +47,12 @@ TanStack Start is powered by the following packages and need to be installed as
- [@tanstack/start](https://github.com/tanstack/start)
- [@tanstack/react-router](https://tanstack.com/router)
-- [Vinxi](https://vinxi.vercel.app/)
-
-> [!NOTE]
-> Vinxi is a temporary dependency that will be replaced by a simple vite plugin or a dedicated Start CLI.
+- [Vite](https://vite.dev/)
To install them, run:
```shell
-npm i @tanstack/react-start @tanstack/react-router vinxi
+npm i @tanstack/react-start @tanstack/react-router vite
```
You'll also need React and the Vite React plugin, so install their dependencies as well:
@@ -72,16 +69,16 @@ npm i -D typescript @types/react @types/react-dom
# Update Configuration Files
-We'll then update our `package.json` to use Vinxi's CLI and set `"type": "module"`:
+We'll then update our `package.json` to use Vite's CLI and set `"type": "module"`:
```jsonc
{
// ...
"type": "module",
"scripts": {
- "dev": "vinxi dev",
- "build": "vinxi build",
- "start": "vinxi start",
+ "dev": "vite dev",
+ "build": "vite build",
+ "start": "vite start",
},
}
```
@@ -97,12 +94,10 @@ export default defineConfig({})
# Add the Basic Templating
-There are four required files for TanStack Start usage:
+There are 2 required files for TanStack Start usage:
1. The router configuration
-2. The server entry point
-3. The client entry point
-4. The root of your application
+2. The root of your application
Once configuration is done, we'll have a file tree that looks like the following:
@@ -111,10 +106,8 @@ Once configuration is done, we'll have a file tree that looks like the following
├── app/
│ ├── routes/
│ │ └── `__root.tsx`
-│ ├── `client.tsx`
│ ├── `router.tsx`
│ ├── `routeTree.gen.ts`
-│ └── `ssr.tsx`
├── `.gitignore`
├── `app.config.ts`
├── `package.json`
@@ -123,7 +116,7 @@ Once configuration is done, we'll have a file tree that looks like the following
## The Router Configuration
-This is the file that will dictate the behavior of TanStack Router used within Start. Here, you can configure everything
+This is the file that will dictate the behavior of TanStack Router used within Start for both the server and the client. Here, you can configure everything
from the default [preloading functionality](./preloading.md) to [caching staleness](./data-loading.md).
```tsx
@@ -149,52 +142,9 @@ declare module '@tanstack/react-router' {
> `routeTree.gen.ts` is not a file you're expected to have at this point.
> It will be generated when you run TanStack Start (via `npm run dev` or `npm run start`) for the first time.
-## The Server Entry Point
-
-As TanStack Start is an [SSR](https://unicorn-utterances.com/posts/what-is-ssr-and-ssg) framework, we need to pipe this router
-information to our server entry point:
-
-```tsx
-// app/ssr.tsx
-import {
- createStartHandler,
- defaultStreamHandler,
-} from '@tanstack/react-start/server'
-import { getRouterManifest } from '@tanstack/react-start/router-manifest'
-
-import { createRouter } from './router'
-
-export default createStartHandler({
- createRouter,
- getRouterManifest,
-})(defaultStreamHandler)
-```
-
-This allows us to know what routes and loaders we need to execute when the user hits a given route.
-
-## The Client Entry Point
-
-Now we need a way to hydrate our client-side JavaScript once the route resolves to the client. We do this by piping the same
-router information to our client entry point:
-
-```tsx
-// app/client.tsx
-import { hydrateRoot } from 'react-dom/client'
-import { StartClient } from '@tanstack/react-start'
-import { createRouter } from './router'
-
-const router = createRouter({
- scrollRestoration: true,
-})
-
-hydrateRoot(document!, )
-```
-
-This enables us to kick off client-side routing once the user's initial server request has fulfilled.
-
## The Root of Your Application
-Finally, we need to create the root of our application. This is the entry point for all other routes. The code in this file will wrap all other routes in the application.
+Finally, we need to create the root of our application. This is the entry point for all application routes. The code in this file will wrap all other routes in the application.
```tsx
// app/routes/__root.tsx
diff --git a/docs/router/framework/react/migrate-from-react-location.md b/docs/router/framework/react/migrate-from-react-location.md
index 100d614cae..ed5914b41f 100644
--- a/docs/router/framework/react/migrate-from-react-location.md
+++ b/docs/router/framework/react/migrate-from-react-location.md
@@ -49,11 +49,11 @@ And add it to your `vite.config.js`:
```js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
export default defineConfig({
// ...
- plugins: [TanStackRouterVite(), react()],
+ plugins: [tanstackRouter(), react()],
})
```
@@ -112,7 +112,7 @@ export const Route = createRootRoute({
// src/routes/index.tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/')({
+export const Route = createFileRoute({
component: Index,
})
```
@@ -125,7 +125,7 @@ export const Route = createFileRoute('/')({
// src/routes/posts.tsx
import { createFileRoute, Link, Outlet } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
component: Posts,
loader: async () => {
const posts = await fetchPosts()
@@ -164,7 +164,7 @@ function Posts() {
// src/routes/posts.index.tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/')({
+export const Route = createFileRoute({
component: PostsIndex,
})
```
@@ -177,7 +177,7 @@ export const Route = createFileRoute('/posts/')({
// src/routes/posts.$postId.tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/$postId')({
+export const Route = createFileRoute({
component: PostsId,
loader: async ({ params: { postId } }) => {
const post = await fetchPost(postId)
diff --git a/docs/router/framework/react/overview.md b/docs/router/framework/react/overview.md
index be83513a79..9e064cf0a1 100644
--- a/docs/router/framework/react/overview.md
+++ b/docs/router/framework/react/overview.md
@@ -42,7 +42,7 @@ It's probably no surprise at this point that picking a router is so important th
**Does this mean that TanStack Router is a framework?**
-TanStack Router itself is not a "framework" in the traditional sense, since it doesn't address a few other common full-stack concerns. However TanStack Router has been designed to be upgradable to a full-stack framework when used in conjunction with other tools that address bundling, deployments, and server-side-specific functionality. This is why we are currently developing [TanStack Start](https://tanstack.com/start), a full-stack framework that is built on top of TanStack Router and tools like Nitro, and Vite.
+TanStack Router itself is not a "framework" in the traditional sense, since it doesn't address a few other common full-stack concerns. However TanStack Router has been designed to be upgradable to a full-stack framework when used in conjunction with other tools that address bundling, deployments, and server-side-specific functionality. This is why we are currently developing [TanStack Start](https://tanstack.com/start), a full-stack framework that is built on top of TanStack Router and Vite.
For a deeper dive on the history of TanStack Router, feel free to read [TanStack Router's History](./decisions-on-dx.md#tanstack-routers-origin-story).
diff --git a/docs/router/framework/react/quick-start.md b/docs/router/framework/react/quick-start.md
index b9264f8742..83a36555e2 100644
--- a/docs/router/framework/react/quick-start.md
+++ b/docs/router/framework/react/quick-start.md
@@ -44,13 +44,17 @@ deno add npm:@tanstack/react-router npm:@tanstack/router-plugin npm:@tanstack/re
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// Please make sure that '@tanstack/router-plugin' is passed before '@vitejs/plugin-react'
- TanStackRouterVite({ target: 'react', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'react',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
react(),
// ...,
],
diff --git a/docs/router/framework/react/routing/installation-with-esbuild.md b/docs/router/framework/react/routing/installation-with-esbuild.md
index 262213f386..da3cd9f857 100644
--- a/docs/router/framework/react/routing/installation-with-esbuild.md
+++ b/docs/router/framework/react/routing/installation-with-esbuild.md
@@ -14,12 +14,16 @@ Once installed, you'll need to add the plugin to your configuration.
```tsx
// esbuild.config.js
-import { TanStackRouterEsbuild } from '@tanstack/router-plugin/esbuild'
+import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
export default {
// ...
plugins: [
- TanStackRouterEsbuild({ target: 'react', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'react',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
],
}
```
@@ -74,6 +78,6 @@ When using the TanStack Router Plugin with Esbuild for File-based routing, it co
}
```
-If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `TanStackRouterEsbuild` function.
+If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `tanstackRouter` function.
You can find all the available configuration options in the [File-based Routing API Reference](../../../api/file-based-routing.md).
diff --git a/docs/router/framework/react/routing/installation-with-rspack.md b/docs/router/framework/react/routing/installation-with-rspack.md
index b118773f86..741978192e 100644
--- a/docs/router/framework/react/routing/installation-with-rspack.md
+++ b/docs/router/framework/react/routing/installation-with-rspack.md
@@ -16,14 +16,18 @@ Once installed, you'll need to add the plugin to your configuration.
// rsbuild.config.ts
import { defineConfig } from '@rsbuild/core'
import { pluginReact } from '@rsbuild/plugin-react'
-import { TanStackRouterRspack } from '@tanstack/router-plugin/rspack'
+import { tanstackRouter } from '@tanstack/router-plugin/rspack'
export default defineConfig({
plugins: [pluginReact()],
tools: {
rspack: {
plugins: [
- TanStackRouterRspack({ target: 'react', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'react',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
],
},
},
@@ -80,6 +84,6 @@ When using the TanStack Router Plugin with Rspack (or Rsbuild) for File-based ro
}
```
-If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `TanStackRouterVite` function.
+If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `tanstackRouter` function.
You can find all the available configuration options in the [File-based Routing API Reference](../../../api/file-based-routing.md).
diff --git a/docs/router/framework/react/routing/installation-with-vite.md b/docs/router/framework/react/routing/installation-with-vite.md
index 00dc2e37d8..a860279372 100644
--- a/docs/router/framework/react/routing/installation-with-vite.md
+++ b/docs/router/framework/react/routing/installation-with-vite.md
@@ -16,13 +16,17 @@ Once installed, you'll need to add the plugin to your Vite configuration.
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// Please make sure that '@tanstack/router-plugin' is passed before '@vitejs/plugin-react'
- TanStackRouterVite({ target: 'react', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'react',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
react(),
// ...
],
@@ -82,6 +86,6 @@ When using the TanStack Router Plugin with Vite for File-based routing, it comes
}
```
-If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `TanStackRouterVite` function.
+If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `tanstackRouter` function.
You can find all the available configuration options in the [File-based Routing API Reference](../../../api/file-based-routing.md).
diff --git a/docs/router/framework/react/routing/installation-with-webpack.md b/docs/router/framework/react/routing/installation-with-webpack.md
index f98a9a1cd2..e89288e2e0 100644
--- a/docs/router/framework/react/routing/installation-with-webpack.md
+++ b/docs/router/framework/react/routing/installation-with-webpack.md
@@ -14,11 +14,15 @@ Once installed, you'll need to add the plugin to your configuration.
```tsx
// webpack.config.ts
-import { TanStackRouterWebpack } from '@tanstack/router-plugin/webpack'
+import { tanstackRouter } from '@tanstack/router-plugin/webpack'
export default {
plugins: [
- TanStackRouterWebpack({ target: 'react', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'react',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
],
}
```
@@ -73,6 +77,6 @@ When using the TanStack Router Plugin with Webpack for File-based routing, it co
}
```
-If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `TanStackRouterWebpack` function.
+If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `tanstackRouter` function.
You can find all the available configuration options in the [File-based Routing API Reference](../../../api/file-based-routing.md).
diff --git a/docs/router/framework/react/routing/routing-concepts.md b/docs/router/framework/react/routing/routing-concepts.md
index 38d9ae5cd9..8ba6969379 100644
--- a/docs/router/framework/react/routing/routing-concepts.md
+++ b/docs/router/framework/react/routing/routing-concepts.md
@@ -13,7 +13,7 @@ All other routes, other than the [Root Route](#the-root-route), are configured u
```tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
component: PostsComponent,
})
```
@@ -71,7 +71,7 @@ Let's take a look at an `/about` route:
// about.tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/about')({
+export const Route = createFileRoute({
component: AboutComponent,
})
@@ -93,7 +93,7 @@ Let's take a look at an index route for a `/posts` URL:
import { createFileRoute } from '@tanstack/react-router'
// Note the trailing slash, which is used to target index routes
-export const Route = createFileRoute('/posts/')({
+export const Route = createFileRoute({
component: PostsIndexComponent,
})
@@ -113,7 +113,7 @@ These params are then usable in your route's configuration and components! Let's
```tsx
import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/$postId')({
+export const Route = createFileRoute({
// In a loader
loader: ({ params }) => fetchPost(params.postId),
// Or in a component
@@ -172,7 +172,7 @@ This tree structure is used to wrap the child routes with a layout component:
```tsx
import { Outlet, createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/app')({
+export const Route = createFileRoute({
component: AppLayoutComponent,
})
@@ -243,7 +243,7 @@ The `_pathlessLayout.tsx` route is used to wrap the child routes with a Pathless
```tsx
import { Outlet, createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/_pathlessLayout')({
+export const Route = createFileRoute({
component: PathlessLayoutComponent,
})
diff --git a/docs/router/framework/react/routing/virtual-file-routes.md b/docs/router/framework/react/routing/virtual-file-routes.md
index d7721989d8..f56fb87891 100644
--- a/docs/router/framework/react/routing/virtual-file-routes.md
+++ b/docs/router/framework/react/routing/virtual-file-routes.md
@@ -53,12 +53,13 @@ If you're using the `TanStackRouter` plugin for Vite/Rspack/Webpack, you can con
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
export default defineConfig({
plugins: [
- TanStackRouterVite({
+ tanstackRouter({
target: 'react',
+ verboseFileRoutes: false,
virtualRouteConfig: './routes.ts',
}),
react(),
@@ -72,7 +73,7 @@ Or, you choose to define the virtual routes directly in the configuration:
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
import { rootRoute } from '@tanstack/virtual-file-routes'
const routes = rootRoute('root.tsx', [
@@ -80,7 +81,7 @@ const routes = rootRoute('root.tsx', [
])
export default defineConfig({
- plugins: [TanStackRouterVite({ virtualRouteConfig: routes }), react()],
+ plugins: [tanstackRouter({ virtualRouteConfig: routes }), react()],
})
```
diff --git a/docs/router/framework/solid/quick-start.md b/docs/router/framework/solid/quick-start.md
index a831b6de1d..4dd822540d 100644
--- a/docs/router/framework/solid/quick-start.md
+++ b/docs/router/framework/solid/quick-start.md
@@ -44,12 +44,16 @@ deno add npm:@tanstack/solid-router npm:@tanstack/router-plugin npm:@tanstack/so
// vite.config.ts
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
- TanStackRouterVite({ target: 'solid', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'solid',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
solid(),
// ...,
],
diff --git a/docs/router/framework/solid/routing/file-based-routing.md b/docs/router/framework/solid/routing/file-based-routing.md
index ffdebc1893..6c15db448e 100644
--- a/docs/router/framework/solid/routing/file-based-routing.md
+++ b/docs/router/framework/solid/routing/file-based-routing.md
@@ -24,12 +24,16 @@ Once installed, you'll need to add the plugin to your Vite configuration.
// vite.config.ts
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
- TanStackRouterVite({ target: 'solid', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'solid',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
solid(),
// ...
],
diff --git a/docs/router/framework/solid/routing/installation-with-vite.md b/docs/router/framework/solid/routing/installation-with-vite.md
index 7c05aaf581..7da230cf16 100644
--- a/docs/router/framework/solid/routing/installation-with-vite.md
+++ b/docs/router/framework/solid/routing/installation-with-vite.md
@@ -16,12 +16,16 @@ Once installed, you'll need to add the plugin to your Vite configuration.
// vite.config.ts
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
-import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
+import { tanstackRouter } from '@tanstack/router-plugin/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
- TanStackRouterVite({ target: 'solid', autoCodeSplitting: true }),
+ tanstackRouter({
+ target: 'solid',
+ autoCodeSplitting: true,
+ verboseFileRoutes: false,
+ }),
solid(),
// ...
],
diff --git a/docs/start/config.json b/docs/start/config.json
index 76cae14ab8..6967df720e 100644
--- a/docs/start/config.json
+++ b/docs/start/config.json
@@ -46,13 +46,17 @@
"to": "framework/react/middleware"
},
{
- "label": "API Routes",
- "to": "framework/react/api-routes"
+ "label": "Server Routes",
+ "to": "framework/react/server-routes"
},
{
"label": "SSR",
"to": "framework/react/ssr"
},
+ {
+ "label": "SPA Mode",
+ "to": "framework/react/spa-mode"
+ },
{
"label": "Hosting",
"to": "framework/react/hosting"
@@ -115,13 +119,17 @@
"to": "framework/solid/middleware"
},
{
- "label": "API Routes",
- "to": "framework/solid/api-routes"
+ "label": "Server Routes",
+ "to": "framework/solid/server-routes"
},
{
"label": "SSR",
"to": "framework/solid/ssr"
},
+ {
+ "label": "SPA Mode",
+ "to": "framework/solid/spa-mode"
+ },
{
"label": "Hosting",
"to": "framework/solid/hosting"
diff --git a/docs/start/framework/react/api-routes.md b/docs/start/framework/react/api-routes.md
deleted file mode 100644
index 87032c5bcd..0000000000
--- a/docs/start/framework/react/api-routes.md
+++ /dev/null
@@ -1,292 +0,0 @@
----
-id: api-routes
-title: API Routes
----
-
-API Routes are a powerful feature of TanStack Start that allow you to create server-side endpoints in your application without the need for a separate server. API Routes are useful for handling form submissions, user authentication, and more.
-
-By default, API Routes are defined in your `./app/routes/api` directory of your project and are automatically handled by the TanStack Start server.
-
-> 🧠 This means that by default, your API Routes will be prefixed with `/api` and will be served from the same server as your application. You can customize this base path by changing the `tsr.apiBase` in your TanStack Start config.
-
-## File Route Conventions
-
-API Routes in TanStack Start, follow the same file-based routing conventions as TanStack Router. This means that each file in your `routes` directory that is prefixed with `api` (which can be configured) will be treated as an API route. Here are a few examples:
-
-- `routes/api.users.ts` will create an API route at `/api/users`
-- `routes/api/users.ts` will **also** create an API route at `/api/users`
-- `routes/api/users.index.ts` will **also** create an API route at `/api/users`
-- `routes/api/users/$id.ts` will create an API route at `/api/users/$id`
-- `routes/api/users/$id/posts.ts` will create an API route at `/api/users/$id/posts`
-- `routes/api.users.$id.posts.ts` will **also** create an API route at `/api/users/$id/posts`
-- `routes/api/file/$.ts` will create an API route at `/api/file/$`
-
-Your route files that are prefixed with `api`, can be thought of as the handlers for the given API route path.
-
-It's important to remember that each route can only have a single handler file associated with it. So, if you have a file named `routes/api/users.ts` which'd equal the request path of `/api/users`, you cannot have other files that'd also resolve to the same route, like:
-
-- `routes/api/users.index.ts`
-- `routes/api.users.ts`.
-- `routes/api.users.index.ts`.
-
-❗ One more thing, API Routes do not have the concept of pathless layout routes or parallel routes. So, a file named:
-
-- `routes/api/_pathlessLayout/users.ts` would resolve to `/api/_pathlessLayout/users` and **NOT** `/api/users`.
-
-## Nested Directories vs File-names
-
-In the examples above, you may have noticed that the file naming conventions are flexible and allow you to mix and match directories and file names. This is intentional and allows you to organize your API Routes in a way that makes sense for your application. You can read more about this in the [TanStack Router File-based Routing Guide](/router/latest/docs/framework/react/routing/file-based-routing#s-or-s).
-
-## Setting up the entry handler
-
-Before you can create your API routes, you need to set up the entry handler for your TanStack Start project. This entry handler, similar to `client` and `ssr`, handles the API incoming requests and routes them to the appropriate API route handler. The API entry handler is defined in the `app/api.ts` file in your project.
-
-Here's an example implementation:
-
-```ts
-// app/api.ts
-import {
- createStartAPIHandler,
- defaultAPIFileRouteHandler,
-} from '@tanstack/react-start/api'
-
-export default createStartAPIHandler(defaultAPIFileRouteHandler)
-```
-
-This file is responsible for creating the API handler that will be used to route incoming requests to the appropriate API route handler. The `defaultAPIFileRouteHandler` is a helper function that will automatically load and execute the appropriate API route handler based on the incoming request.
-
-## Defining an API Route
-
-API Routes export an APIRoute instance by calling the `createAPIFileRoute` function. Similar to other file-based routes in TanStack Router, the first argument to this function is the path of the route. The function returned is called again with an object that defines the route handlers for each HTTP method.
-
-> [!TIP]
-> If you've already got the dev server running, when you create a new API route, it'll automatically have the initial handler set up for you. From there on, you can customize the handler as needed.
-
-> [!NOTE]
-> The export variable must be named `APIRoute` or the resulting response will be a `404 not found`.
-
-```ts
-// routes/api/hello.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/api/hello')({
- GET: async ({ request }) => {
- return new Response('Hello, World! from ' + request.url)
- },
-})
-```
-
-Each HTTP method handler receives an object with the following properties:
-
-- `request`: The incoming request object. You can read more about the `Request` object in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Request).
-- `params`: An object containing the dynamic path parameters of the route. For example, if the route path is `/users/$id`, and the request is made to `/users/123`, then `params` will be `{ id: '123' }`. We'll cover dynamic path parameters and wildcard parameters later in this guide.
-
-Once you've processed the request, you need to return a `Response` object or `Promise`. This can be done by creating a new `Response` object and returning it from the handler. You can read more about the `Response` object in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Response).
-
-## Dynamic Path Params
-
-API Routes support dynamic path parameters, which are denoted by a `$` followed by the parameter name. For example, a file named `routes/api/users/$id.ts` will create an API route at `/api/users/$id` that accepts a dynamic `id` parameter.
-
-```ts
-// routes/api/users/$id.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/users/$id')({
- GET: async ({ params }) => {
- const { id } = params
- return new Response(`User ID: ${id}`)
- },
-})
-
-// Visit /api/users/123 to see the response
-// User ID: 123
-```
-
-You can also have multiple dynamic path parameters in a single route. For example, a file named `routes/api/users/$id/posts/$postId.ts` will create an API route at `/api/users/$id/posts/$postId` that accepts two dynamic parameters.
-
-```ts
-// routes/api/users/$id/posts/$postId.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/users/$id/posts/$postId')({
- GET: async ({ params }) => {
- const { id, postId } = params
- return new Response(`User ID: ${id}, Post ID: ${postId}`)
- },
-})
-
-// Visit /api/users/123/posts/456 to see the response
-// User ID: 123, Post ID: 456
-```
-
-## Wildcard/Splat Param
-
-API Routes also support wildcard parameters at the end of the path, which are denoted by a `$` followed by nothing. For example, a file named `routes/api/file/$.ts` will create an API route at `/api/file/$` that accepts a wildcard parameter.
-
-```ts
-// routes/api/file/$.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/file/$')({
- GET: async ({ params }) => {
- const { _splat } = params
- return new Response(`File: ${_splat}`)
- },
-})
-
-// Visit /api/file/hello.txt to see the response
-// File: hello.txt
-```
-
-## Handling requests with a body
-
-To handle POST requests,you can add a `POST` handler to the route object. The handler will receive the request object as the first argument, and you can access the request body using the `request.json()` method.
-
-```ts
-// routes/api/hello.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/api/hello')({
- POST: async ({ request }) => {
- const body = await request.json()
- return new Response(`Hello, ${body.name}!`)
- },
-})
-
-// Send a POST request to /api/hello with a JSON body like { "name": "Tanner" }
-// Hello, Tanner!
-```
-
-This also applies to other HTTP methods like `PUT`, `PATCH`, and `DELETE`. You can add handlers for these methods in the route object and access the request body using the appropriate method.
-
-It's important to remember that the `request.json()` method returns a `Promise` that resolves to the parsed JSON body of the request. You need to `await` the result to access the body.
-
-This is a common pattern for handling POST requests in API Routes. You can also use other methods like `request.text()` or `request.formData()` to access the body of the request.
-
-## Responding with JSON
-
-When returning JSON using a Response object, this is a common pattern:
-
-```ts
-// routes/api/hello.ts
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/api/hello')({
- GET: async ({ request }) => {
- return new Response(JSON.stringify({ message: 'Hello, World!' }), {
- headers: {
- 'Content-Type': 'application/json',
- },
- })
- },
-})
-
-// Visit /api/hello to see the response
-// {"message":"Hello, World!"}
-```
-
-## Using the `json` helper function
-
-Or you can use the `json` helper function to automatically set the `Content-Type` header to `application/json` and serialize the JSON object for you.
-
-```ts
-// routes/api/hello.ts
-import { json } from '@tanstack/react-start'
-import { createAPIFileRoute } from '@tanstack/react-start/api'
-
-export const APIRoute = createAPIFileRoute('/api/hello')({
- GET: async ({ request }) => {
- return json({ message: 'Hello, World!' })
- },
-})
-
-// Visit /api/hello to see the response
-// {"message":"Hello, World!"}
-```
-
-## Responding with a status code
-
-You can set the status code of the response by either:
-
-- Passing it as a property of the second argument to the `Response` constructor
-
- ```ts
- // routes/api/hello.ts
- import { json } from '@tanstack/react-start'
- import { createAPIFileRoute } from '@tanstack/react-start/api'
-
- export const APIRoute = createAPIFileRoute('/users/$id')({
- GET: async ({ request, params }) => {
- const user = await findUser(params.id)
- if (!user) {
- return new Response('User not found', {
- status: 404,
- })
- }
- return json(user)
- },
- })
- ```
-
-- Using the `setResponseStatus` helper function from `@tanstack/react-start/server`
-
- ```ts
- // routes/api/hello.ts
- import { json } from '@tanstack/react-start'
- import { createAPIFileRoute } from '@tanstack/react-start/api'
- import { setResponseStatus } from '@tanstack/react-start/server'
-
- export const APIRoute = createAPIFileRoute('/users/$id')({
- GET: async ({ request, params }) => {
- const user = await findUser(params.id)
- if (!user) {
- setResponseStatus(404)
- return new Response('User not found')
- }
- return json(user)
- },
- })
- ```
-
-In this example, we're returning a `404` status code if the user is not found. You can set any valid HTTP status code using this method.
-
-## Setting headers in the response
-
-Sometimes you may need to set headers in the response. You can do this by either:
-
-- Passing an object as the second argument to the `Response` constructor.
-
- ```ts
- // routes/api/hello.ts
- import { createAPIFileRoute } from '@tanstack/react-start/api'
-
- export const APIRoute = createAPIFileRoute('/api/hello')({
- GET: async ({ request }) => {
- return new Response('Hello, World!', {
- headers: {
- 'Content-Type': 'text/plain',
- },
- })
- },
- })
-
- // Visit /api/hello to see the response
- // Hello, World!
- ```
-
-- Or using the `setHeaders` helper function from `@tanstack/react-start/server`.
-
- ```ts
- // routes/api/hello.ts
- import { createAPIFileRoute } from '@tanstack/react-start/api'
- import { setHeaders } from '@tanstack/react-start/server'
-
- export const APIRoute = createAPIFileRoute('/api/hello')({
- GET: async ({ request }) => {
- setHeaders({
- 'Content-Type': 'text/plain',
- })
- return new Response('Hello, World!')
- },
- })
- ```
diff --git a/docs/start/framework/react/authentication.md b/docs/start/framework/react/authentication.md
index fe90ebbcff..8d4ed86236 100644
--- a/docs/start/framework/react/authentication.md
+++ b/docs/start/framework/react/authentication.md
@@ -17,9 +17,9 @@ That said, authentication is not something to be taken lightly. After much vetti
-
-
-
+
+
+
diff --git a/docs/start/framework/react/build-from-scratch.md b/docs/start/framework/react/build-from-scratch.md
index 055526d7f8..6143199b6c 100644
--- a/docs/start/framework/react/build-from-scratch.md
+++ b/docs/start/framework/react/build-from-scratch.md
@@ -4,7 +4,7 @@ title: Build a Project from Scratch
---
> [!NOTE]
-> If you chose to quick start with an example or cloned project, you can skip this guide and move on to the [Learn the Basics](../learn-the-basics) guide.
+> If you chose to quick start with an example or cloned project, you can skip this guide and move on to the [Learn the Basics](./learn-the-basics.md) guide.
_So you want to build a TanStack Start project from scratch?_
@@ -47,85 +47,75 @@ We highly recommend using TypeScript with TanStack Start. Create a `tsconfig.jso
## Install Dependencies
-TanStack Start is (currently\*) powered by [Vinxi](https://vinxi.vercel.app/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
-
-> [!NOTE] > \*Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin or dedicated TanStack Start CLI.
+TanStack Start is powered by [Vite](https://vite.dev/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
To install them, run:
```shell
-npm i @tanstack/react-start @tanstack/react-router vinxi
+npm i @tanstack/react-start @tanstack/react-router vite
```
-You'll also need React and the Vite React plugin, so install them too:
+You'll also need React:
```shell
npm i react react-dom
-npm i -D @vitejs/plugin-react vite-tsconfig-paths
```
and some TypeScript:
```shell
-npm i -D typescript @types/react @types/react-dom
+npm i -D typescript @types/react @types/react-dom vite-tsconfig-paths
```
## Update Configuration Files
-We'll then update our `package.json` to use Vinxi's CLI and set `"type": "module"`:
+We'll then update our `package.json` to use Vite's CLI and set `"type": "module"`:
```json
{
// ...
"type": "module",
"scripts": {
- "dev": "vinxi dev",
- "build": "vinxi build",
- "start": "vinxi start"
+ "dev": "vite dev",
+ "build": "vite build"
}
}
```
-Then configure TanStack Start's `app.config.ts` file:
+Then configure TanStack Start's Vite plugin in `vite.config.ts`:
-```typescript
-// app.config.ts
-import { defineConfig } from '@tanstack/react-start/config'
+```ts
+// vite.config.ts
+import { defineConfig } from 'vite'
import tsConfigPaths from 'vite-tsconfig-paths'
+import { tanstackStart } from '@tanstack/react-start/plugin/vite'
export default defineConfig({
- vite: {
- plugins: [
- tsConfigPaths({
- projects: ['./tsconfig.json'],
- }),
- ],
+ server: {
+ port: 3000,
},
+ plugins: [tsConfigPaths(), tanstackStart()],
})
```
## Add the Basic Templating
-There are four required files for TanStack Start usage:
+There are 2 required files for TanStack Start usage:
1. The router configuration
-2. The server entry point
-3. The client entry point
-4. The root of your application
+2. The root of your application
Once configuration is done, we'll have a file tree that looks like the following:
```
.
-├── app/
+├── src/
│ ├── routes/
│ │ └── `__root.tsx`
-│ ├── `client.tsx`
│ ├── `router.tsx`
│ ├── `routeTree.gen.ts`
-│ └── `ssr.tsx`
├── `.gitignore`
-├── `app.config.ts`
+├── `vite.config.ts`
├── `package.json`
└── `tsconfig.json`
```
@@ -139,7 +129,7 @@ from the default [preloading functionality](/router/latest/docs/framework/react/
> You won't have a `routeTree.gen.ts` file yet. This file will be generated when you run TanStack Start for the first time.
```tsx
-// app/router.tsx
+// src/router.tsx
import { createRouter as createTanStackRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
@@ -159,54 +149,12 @@ declare module '@tanstack/react-router' {
}
```
-## The Server Entry Point
-
-As TanStack Start is an [SSR](https://unicorn-utterances.com/posts/what-is-ssr-and-ssg) framework, we need to pipe this router
-information to our server entry point:
-
-```tsx
-// app/ssr.tsx
-import {
- createStartHandler,
- defaultStreamHandler,
-} from '@tanstack/react-start/server'
-import { getRouterManifest } from '@tanstack/react-start/router-manifest'
-
-import { createRouter } from './router'
-
-export default createStartHandler({
- createRouter,
- getRouterManifest,
-})(defaultStreamHandler)
-```
-
-This allows us to know what routes and loaders we need to execute when the user hits a given route.
-
-## The Client Entry Point
-
-Now we need a way to hydrate our client-side JavaScript once the route resolves to the client. We do this by piping the same
-router information to our client entry point:
-
-```tsx
-// app/client.tsx
-///
-import { hydrateRoot } from 'react-dom/client'
-import { StartClient } from '@tanstack/react-start'
-import { createRouter } from './router'
-
-const router = createRouter()
-
-hydrateRoot(document, )
-```
-
-This enables us to kick off client-side routing once the user's initial server request has fulfilled.
-
## The Root of Your Application
Finally, we need to create the root of our application. This is the entry point for all other routes. The code in this file will wrap all other routes in the application.
```tsx
-// app/routes/__root.tsx
+// src/routes/__root.tsx
import type { ReactNode } from 'react'
import {
Outlet,
@@ -258,12 +206,12 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
## Writing Your First Route
-Now that we have the basic templating setup, we can write our first route. This is done by creating a new file in the `app/routes` directory.
+Now that we have the basic templating setup, we can write our first route. This is done by creating a new file in the `src/routes` directory.
```tsx
-// app/routes/index.tsx
+// src/routes/index.tsx
import * as fs from 'node:fs'
-import { createFileRoute, useRouter } from '@tanstack/react-router'
+import { useRouter } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/react-start'
const filePath = 'count.txt'
@@ -287,7 +235,7 @@ const updateCount = createServerFn({ method: 'POST' })
await fs.promises.writeFile(filePath, `${count + data}`)
})
-export const Route = createFileRoute('/')({
+export const Route = createFileRoute({
component: Home,
loader: async () => await getCount(),
})
diff --git a/docs/start/framework/react/databases.md b/docs/start/framework/react/databases.md
index 6f6aba34bd..e2a0bc42de 100644
--- a/docs/start/framework/react/databases.md
+++ b/docs/start/framework/react/databases.md
@@ -41,9 +41,9 @@ While TanStack Start is designed to work with any database provider, we highly r
-
-
-
+
+
+
@@ -65,9 +65,9 @@ Key features that make Neon stand out:
-
-
-
+
+
+
diff --git a/docs/start/framework/react/hosting.md b/docs/start/framework/react/hosting.md
index 5241494e80..85d3185d0a 100644
--- a/docs/start/framework/react/hosting.md
+++ b/docs/start/framework/react/hosting.md
@@ -3,7 +3,7 @@ id: hosting
title: Hosting
---
-Hosting is the process of deploying your application to the internet so that users can access it. This is a critical part of any web development project, ensuring your application is available to the world. TanStack Start is built on [Nitro](https://nitro.unjs.io/), a powerful server toolkit for deploying web applications anywhere. Nitro allows TanStack Start to provide a unified API for SSR, streaming, and hydration on any hosting provider.
+Hosting is the process of deploying your application to the internet so that users can access it. This is a critical part of any web development project, ensuring your application is available to the world. TanStack Start is built on Vite, a powerful dev/build platform that allows us to make it possible to deploy your application to any hosting provider.
## What should I use?
@@ -15,9 +15,9 @@ However, since hosting is one of the most crucial aspects of your application's
-
-
-
+
+
+
@@ -31,7 +31,7 @@ Netlify is a leading hosting platform that provides a fast, secure, and reliable
> [!WARNING]
> The page is still a work in progress. We'll keep updating this page with guides on deployment to different hosting providers soon!
-When a TanStack Start application is being deployed, the `server.preset` value in the `app.config.ts` file determines the deployment target. The deployment target can be set to one of the following values:
+When a TanStack Start application is being deployed, the `target` value in the TanStack Start Vite plugin in the`vite.config.ts` file determines the deployment target. The deployment target can be set to one of the following values:
- [`netlify`](#netlify): Deploy to Netlify
- [`vercel`](#vercel): Deploy to Vercel
@@ -44,48 +44,34 @@ Once you've chosen a deployment target, you can follow the deployment guidelines
### Netlify
-Set the `server.preset` value to `netlify` in your `app.config.ts` file.
+Set the `target` value to `'netlify'` in the TanStack Start Vite plugin in `vite.config.ts` file.
```ts
-// app.config.ts
-import { defineConfig } from '@tanstack/react-start/config'
+// vite.config.ts
+import { tanstackStart } from '@tanstack/react-start/plugin/vite'
+import { defineConfig } from 'vite'
export default defineConfig({
- server: {
- preset: 'netlify',
- },
+ plugins: [tanstackStart({ target: 'netlify' })],
})
```
-Or you can use the `--preset` flag with the `build` command to specify the deployment target when building the application:
-
-```sh
-npm run build --preset netlify
-```
-
Deploy your application to Netlify using their one-click deployment process, and you're ready to go!
### Vercel
-Deploying your TanStack Start application to Vercel is easy and straightforward. Just set the `server.preset` value to `vercel` in your `app.config.ts` file, and you're ready to deploy your application to Vercel.
+Set the `target` value to `'vercel'` in the TanStack Start Vite plugin in `vite.config.ts` file.
```ts
-// app.config.ts
-import { defineConfig } from '@tanstack/react-start/config'
+// vite.config.ts
+import { tanstackStart } from '@tanstack/react-start/plugin/vite'
+import { defineConfig } from 'vite'
export default defineConfig({
- server: {
- preset: 'vercel',
- },
+ plugins: [tanstackStart({ target: 'vercel' })],
})
```
-Or you can use the `--preset` flag with the `build` command to specify the deployment target when building the application:
-
-```sh
-npm run build --preset vercel
-```
-
Deploy your application to Vercel using their one-click deployment process, and you're ready to go!
### Cloudflare Pages
diff --git a/docs/start/framework/react/learn-the-basics.md b/docs/start/framework/react/learn-the-basics.md
index cc00141883..a3da690428 100644
--- a/docs/start/framework/react/learn-the-basics.md
+++ b/docs/start/framework/react/learn-the-basics.md
@@ -7,13 +7,10 @@ This guide will help you learn the basics behind how TanStack Start works, regar
## Dependencies
-TanStack Start is (currently\*) powered by [Vinxi](https://vinxi.vercel.app/), [Nitro](https://nitro.unjs.io/) and [TanStack Router](https://tanstack.com/router).
+TanStack Start is powered by [Vite](https://vite.dev/) and [TanStack Router](https://tanstack.com/router).
- **TanStack Router**: A router for building web applications.
-- **Nitro**: A framework for building server applications.
-- **Vinxi**: A server framework for building web applications.
-
-> [!NOTE] Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin.
+- **Vite**: A build tool for bundling your application.
## It all "Starts" with the Router
@@ -47,54 +44,60 @@ declare module '@tanstack/react-router' {
The `routeTree.gen.ts` file is generated when you run TanStack Start (via `npm run dev` or `npm run start`) for the first time. This file contains the generated route tree and a handful of TS utilities that make TanStack Start fully type-safe.
-## The Server Entry Point
+## The Server Entry Point (Optional)
-Although TanStack Start is designed with client-first APIs, it is by and large, a full-stack framework. This means that all use cases, including both dynamic and static rely on a server or build-time entry to render our application's initial HTML payload.
+> [!NOTE]
+> The server entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the server entry point for you using the below as a default.
-This is done via the `app/ssr.tsx` file:
+This is done via the `src/server.ts` file:
```tsx
-// app/ssr.tsx
+// src/server.ts
import {
createStartHandler,
defaultStreamHandler,
} from '@tanstack/react-start/server'
-import { getRouterManifest } from '@tanstack/react-start/router-manifest'
-
import { createRouter } from './router'
export default createStartHandler({
createRouter,
- getRouterManifest,
})(defaultStreamHandler)
```
-Whether we are statically generating our app or serving it dynamically, the `ssr.tsx` file is the entry point for doing all SSR-related work.
+Whether we are statically generating our app or serving it dynamically, the `server.ts` file is the entry point for doing all SSR-related work.
- It's important that a new router is created for each request. This ensures that any data handled by the router is unique to the request.
-- The `getRouterManifest` function is used to generate the router manifest, which is used to determine many aspects of asset management and preloading for our application.
- The `defaultStreamHandler` function is used to render our application to a stream, allowing us to take advantage of streaming HTML to the client. (This is the default handler, but you can also use other handlers like `defaultRenderHandler`, or even build your own)
-## The Client Entry Point
+## The Client Entry Point (Optional)
+
+> [!NOTE]
+> The client entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the client entry point for you using the below as a default.
Getting our html to the client is only half the battle. Once there, we need to hydrate our client-side JavaScript once the route resolves to the client. We do this by hydrating the root of our application with the `StartClient` component:
```tsx
// app/client.tsx
-import { hydrateRoot } from 'react-dom/client'
import { StartClient } from '@tanstack/react-start'
+import { StrictMode } from 'react'
+import { hydrateRoot } from 'react-dom/client'
import { createRouter } from './router'
const router = createRouter()
-hydrateRoot(document, )
+hydrateRoot(
+ document,
+
+
+ ,
+)
```
This enables us to kick off client-side routing once the user's initial server request has fulfilled.
## The Root of Your Application
-Other than the client entry point, the `__root` route of your application is the entry point for your application. The code in this file will wrap all other routes in the app, including your home page. It behaves like a pathless layout route for your whole application.
+Other than the client entry point (which is optional by default), the `__root` route of your application is the entry point for your application. The code in this file will wrap all other routes in the app, including your home page. It behaves like a pathless layout route for your whole application.
Because it is **always rendered**, it is the perfect place to construct your application shell and take care of any global logic.
diff --git a/docs/start/framework/react/middleware.md b/docs/start/framework/react/middleware.md
index 7eb75ba032..9877da95fd 100644
--- a/docs/start/framework/react/middleware.md
+++ b/docs/start/framework/react/middleware.md
@@ -24,12 +24,14 @@ Middleware is defined using the `createMiddleware` function. This function retur
```tsx
import { createMiddleware } from '@tanstack/react-start'
-const loggingMiddleware = createMiddleware().server(async ({ next, data }) => {
- console.log('Request received:', data)
- const result = await next()
- console.log('Response processed:', result)
- return result
-})
+const loggingMiddleware = createMiddleware({ type: 'function' }).server(
+ async ({ next, data }) => {
+ console.log('Request received:', data)
+ const result = await next()
+ console.log('Response processed:', result)
+ return result
+ },
+)
```
## Using Middleware in Your Server Functions
@@ -63,7 +65,7 @@ The `middleware` method is used to dependency middleware to the chain that will
```tsx
import { createMiddleware } from '@tanstack/react-start'
-const loggingMiddleware = createMiddleware().middleware([
+const loggingMiddleware = createMiddleware({ type: 'function' }).middleware([
authMiddleware,
loggingMiddleware,
])
@@ -84,7 +86,7 @@ const mySchema = z.object({
workspaceId: z.string(),
})
-const workspaceMiddleware = createMiddleware()
+const workspaceMiddleware = createMiddleware({ type: 'function' })
.validator(zodValidator(mySchema))
.server(({ next, data }) => {
console.log('Workspace ID:', data.workspaceId)
@@ -107,12 +109,14 @@ The `next` function is used to execute the next middleware in the chain. **You m
```tsx
import { createMiddleware } from '@tanstack/react-start'
-const loggingMiddleware = createMiddleware().server(async ({ next }) => {
- console.log('Request received')
- const result = await next()
- console.log('Response processed')
- return result
-})
+const loggingMiddleware = createMiddleware({ type: 'function' }).server(
+ async ({ next }) => {
+ console.log('Request received')
+ const result = await next()
+ console.log('Response processed')
+ return result
+ },
+)
```
## Providing context to the next middleware via `next`
@@ -122,15 +126,17 @@ The `next` function can be optionally called with an object that has a `context`
```tsx
import { createMiddleware } from '@tanstack/react-start'
-const awesomeMiddleware = createMiddleware().server(({ next }) => {
- return next({
- context: {
- isAwesome: Math.random() > 0.5,
- },
- })
-})
+const awesomeMiddleware = createMiddleware({ type: 'function' }).server(
+ ({ next }) => {
+ return next({
+ context: {
+ isAwesome: Math.random() > 0.5,
+ },
+ })
+ },
+)
-const loggingMiddleware = createMiddleware().server(
+const loggingMiddleware = createMiddleware({ type: 'function' }).server(
async ({ next, context }) => {
console.log('Is awesome?', context.isAwesome)
return next()
@@ -180,12 +186,14 @@ Similar to the `server` function, it also receives an object with the following
- `context`: An object that stores data from parent middleware. It can be extended with additional data that will be passed to child middleware.
```tsx
-const loggingMiddleware = createMiddleware().client(async ({ next }) => {
- console.log('Request sent')
- const result = await next()
- console.log('Response received')
- return result
-})
+const loggingMiddleware = createMiddleware({ type: 'function' }).client(
+ async ({ next }) => {
+ console.log('Request sent')
+ const result = await next()
+ console.log('Response received')
+ return result
+ },
+)
```
## Sending client context to the server
@@ -193,7 +201,7 @@ const loggingMiddleware = createMiddleware().client(async ({ next }) => {
**Client context is NOT sent to the server by default since this could end up unintentionally sending large payloads to the server.** If you need to send client context to the server, you must call the `next` function with a `sendContext` property and object to transmit any data to the server. Any properties passed to `sendContext` will be merged, serialized and sent to the server along with the data and will be available on the normal context object of any nested server middleware.
```tsx
-const requestLogger = createMiddleware()
+const requestLogger = createMiddleware({ type: 'function' })
.client(async ({ next, context }) => {
return next({
sendContext: {
@@ -217,7 +225,7 @@ You may have noticed that in the example above that while client-sent context is
import { zodValidator } from '@tanstack/zod-adapter'
import { z } from 'zod'
-const requestLogger = createMiddleware()
+const requestLogger = createMiddleware({ type: 'function' })
.client(async ({ next, context }) => {
return next({
sendContext: {
@@ -241,16 +249,18 @@ Similar to sending client context to the server, you can also send server contex
> The return type of `next` in `client` can only be inferred from middleware known in the current middleware chain. Therefore the most accurate return type of `next` is in middleware at the end of the middleware chain
```tsx
-const serverTimer = createMiddleware().server(async ({ next }) => {
- return next({
- sendContext: {
- // Send the current time to the client
- timeFromServer: new Date(),
- },
- })
-})
+const serverTimer = createMiddleware({ type: 'function' }).server(
+ async ({ next }) => {
+ return next({
+ sendContext: {
+ // Send the current time to the client
+ timeFromServer: new Date(),
+ },
+ })
+ },
+)
-const requestLogger = createMiddleware()
+const requestLogger = createMiddleware({ type: 'function' })
.middleware([serverTimer])
.client(async ({ next }) => {
const result = await next()
@@ -276,13 +286,15 @@ Here's an example of adding an `Authorization` header any request using this mid
```tsx
import { getToken } from 'my-auth-library'
-const authMiddleware = createMiddleware().client(async ({ next }) => {
- return next({
- headers: {
- Authorization: `Bearer ${getToken()}`,
- },
- })
-})
+const authMiddleware = createMiddleware({ type: 'function' }).client(
+ async ({ next }) => {
+ return next({
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ },
+ })
+ },
+)
```
## Using Middleware
@@ -323,10 +335,12 @@ registerGlobalMiddleware({
```tsx
// authMiddleware.ts
-const authMiddleware = createMiddleware().server(({ next, context }) => {
- console.log(context.user) // <-- This will not be typed!
- // ...
-})
+const authMiddleware = createMiddleware({ type: 'function' }).server(
+ ({ next, context }) => {
+ console.log(context.user) // <-- This will not be typed!
+ // ...
+ },
+)
```
To solve this, add the global middleware you are trying to reference to the server function's middleware array. **The global middleware will be deduped to a single entry (the global instance), and your server function will receive the correct types.**
@@ -356,40 +370,44 @@ Middleware is executed dependency-first, starting with global middleware, follow
- `d`
```tsx
-const globalMiddleware1 = createMiddleware().server(async ({ next }) => {
- console.log('globalMiddleware1')
- return next()
-})
+const globalMiddleware1 = createMiddleware({ type: 'function' }).server(
+ async ({ next }) => {
+ console.log('globalMiddleware1')
+ return next()
+ },
+)
-const globalMiddleware2 = createMiddleware().server(async ({ next }) => {
- console.log('globalMiddleware2')
- return next()
-})
+const globalMiddleware2 = createMiddleware({ type: 'function' }).server(
+ async ({ next }) => {
+ console.log('globalMiddleware2')
+ return next()
+ },
+)
registerGlobalMiddleware({
middleware: [globalMiddleware1, globalMiddleware2],
})
-const a = createMiddleware().server(async ({ next }) => {
+const a = createMiddleware({ type: 'function' }).server(async ({ next }) => {
console.log('a')
return next()
})
-const b = createMiddleware()
+const b = createMiddleware({ type: 'function' })
.middleware([a])
.server(async ({ next }) => {
console.log('b')
return next()
})
-const c = createMiddleware()
+const c = createMiddleware({ type: 'function' })
.middleware()
.server(async ({ next }) => {
console.log('c')
return next()
})
-const d = createMiddleware()
+const d = createMiddleware({ type: 'function' })
.middleware([b, c])
.server(async () => {
console.log('d')
diff --git a/docs/start/framework/react/observability.md b/docs/start/framework/react/observability.md
index fb483ba814..78e6a2dff3 100644
--- a/docs/start/framework/react/observability.md
+++ b/docs/start/framework/react/observability.md
@@ -15,9 +15,9 @@ However, for the best observability experience, we highly recommend using [Sentr
-
-
-
+
+
+
diff --git a/docs/start/framework/react/overview.md b/docs/start/framework/react/overview.md
index ca4bbac835..30f0388822 100644
--- a/docs/start/framework/react/overview.md
+++ b/docs/start/framework/react/overview.md
@@ -3,7 +3,7 @@ id: overview
title: TanStack Start Overview
---
-TanStack Start is a full-stack React framework powered by TanStack Router. It provides a full-document SSR, streaming, server functions, bundling, and more using tools like [Nitro](https://nitro.unjs.io/) and [Vite](https://vitejs.dev/). It is ready to deploy to your favorite hosting provider!
+TanStack Start is a full-stack React framework powered by TanStack Router. It provides a full-document SSR, streaming, server functions, bundling, and more. Thanks to [Vite](https://vite.dev/), it's ready to develop and deploy to any hosting provider or runtime you want!
## Router or Start?
@@ -39,7 +39,7 @@ What you get with TanStack Start:
## How does it work?
-TanStack Start uses [Nitro](https://nitro.unjs.io/) and [Vite](https://vitejs.dev/) to bundle and deploy your application. In fact, these are the same tools that power Solid Start! With these tools, we can do a few things we couldn't do before:
+TanStack Start uses [Vite](https://vitejs.dev/) to bundle and deploy your application and empowers amazing features like:
- Provide a unified API for SSR, streaming, and hydration
- Extract server-only code from your client-side code (e.g. server functions)
@@ -71,45 +71,45 @@ TanStack works closely with our partners to provide the best possible developer
- **Clerk**
-
-
-
+
+
+
The best possible authentication experience for modern web applications, including TanStack Start applications. Clerk provides TanStack Start users with first-class integrations and solutions to auth and collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in auth best practices.
- **Netlify**
-
-
-
+
+
+
The leading hosting platform for web applications that provides a fast, secure, and reliable environment for deploying your web applications. We work closely with Netlify to ensure that TanStack Start applications not only deploy seamlessly to their platform, but also implement best practices for performance, security, and reliability regardless of where you end up deploying.
- **Neon**
-
-
-
+
+
+
A serverless, autoscaling Postgres solution purpose-built for modern full-stack apps. Neon offers rich integration opportunities with TanStack Start, including server functions and database-backed routing. Together, we’re simplifying the database experience for developers using TanStack.
- **Convex**
-
-
-
+
+
+
A serverless database platform that integrates seamlessly with TanStack Start. Convex is designed to simplify the process of managing your application's data and provides a real-time, scalable, and transactional data backend that works well with TanStack Start applications. Convex also collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in database best practices.
- **Sentry**
-
-
-
+
+
+
A powerful, full-featured observability platform that integrates seamlessly with TanStack Start. Sentry helps developers monitor and fix crashes in real-time and provides insights into your application's performance and error tracking. Sentry collaborates closely with the TanStack team to ensure that TanStack Start provides APIs that are up to date with the latest in observability best practices.
diff --git a/docs/start/framework/react/server-functions.md b/docs/start/framework/react/server-functions.md
index 61c97a5080..26a99a8c94 100644
--- a/docs/start/framework/react/server-functions.md
+++ b/docs/start/framework/react/server-functions.md
@@ -8,7 +8,7 @@ title: Server Functions
Server functions allow you to specify logic that can be invoked almost anywhere (even the client), but run **only** on the server. In fact, they are not so different from an API Route, but with a few key differences:
- They do not have stable public URL (but you'll be able to do this very soon!)
-- They can be called from anywhere in your application, including loaders, hooks, components, etc., but cannot be called from API Routes.
+- They can be called from anywhere in your application, including loaders, hooks, components, server routes etc.
However, they are similar to regular API Routes in that:
diff --git a/docs/start/framework/react/server-routes.md b/docs/start/framework/react/server-routes.md
new file mode 100644
index 0000000000..9b905a1802
--- /dev/null
+++ b/docs/start/framework/react/server-routes.md
@@ -0,0 +1,382 @@
+---
+id: server-routes
+title: Server Routes
+---
+
+// TODO: Add redirect from api-routes to server-routes
+
+Server routes are a powerful feature of TanStack Start that allow you to create server-side endpoints in your application and are useful for handling raw HTTP requests, form submissions, user authentication, and much more.
+
+Server routes can be defined in your `./src/routes` directory of your project **right alongside your TanStack Router routes** and are automatically handled by the TanStack Start server.
+
+Here's what a simple server route looks like:
+
+```ts
+// routes/hello.ts
+
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return new Response('Hello, World!')
+ },
+})
+```
+
+## Server Routes and App Routes
+
+Because server routes can be defined in the same directory as your app routes, you can even use the same file for both!
+
+```tsx
+// routes/hello.tsx
+
+export const ServerRoute = createServerFileRoute().methods({
+ POST: async ({ request }) => {
+ const body = await request.json()
+ return new Response(JSON.stringify({ message: `Hello, ${body.name}!` }))
+ },
+})
+
+export const Route = createFileRoute({
+ component: HelloComponent,
+})
+
+function HelloComponent() {
+ const [reply, setReply] = useState('')
+
+ return (
+
+
+
+ )
+}
+```
+
+## File Route Conventions
+
+Server routes in TanStack Start, follow the same file-based routing conventions as TanStack Router. This means that each file in your `routes` directory with a `ServerRoute` export will be treated as an API route. Here are a few examples:
+
+- `/routes/users.ts` will create an API route at `/users`
+- `/routes/users.index.ts` will **also** create an API route at `/users` (but will error if duplicate methods are defined)
+- `/routes/users/$id.ts` will create an API route at `/users/$id`
+- `/routes/users/$id/posts.ts` will create an API route at `/users/$id/posts`
+- `/routes/users.$id.posts.ts` will create an API route at `/users/$id/posts`
+- `/routes/file/$.ts` will create an API route at `/api/file/$`
+- `/routes/my-script[.]js.ts` will create an API route at `/my-script.js`
+
+## Unique Route Paths
+
+Each route can only have a single handler file associated with it. So, if you have a file named `routes/users.ts` which'd equal the request path of `/api/users`, you cannot have other files that'd also resolve to the same route. For example, the following files would all resolve to the same route and would error:
+
+- `/routes/users.index.ts`
+- `/routes/users.ts`
+- `/routes/users.index.ts`
+
+## Escaped Matching
+
+Just as with normal routes, server routes can match on escaped characters. For example, a file named `routes/users[.]json.ts` will create an API route at `/api/users[.]json`.
+
+## Pathless Layout Routes and Break-out Routes
+
+Because of the unified routing system, pathless layout routes and break-out routes are supported for similar functionality around server route middleware.
+
+- Pathless layout routes can be used to add middleware to a group of routes
+- Break-out routes can be used to "break out" of parent middleware
+
+## Nested Directories vs File-names
+
+In the examples above, you may have noticed that the file naming conventions are flexible and allow you to mix and match directories and file names. This is intentional and allows you to organize your Server routes in a way that makes sense for your application. You can read more about this in the [TanStack Router File-based Routing Guide](/router/latest/docs/framework/react/routing/file-based-routing#s-or-s).
+
+## Handling Server Route Requests
+
+Server route requests are handled by Start's `createStartHandler` in your `server.ts` entry file.
+
+```tsx
+// server.ts
+import {
+ createStartHandler,
+ defaultStreamHandler,
+} from '@tanstack/react-start/server'
+import { createRouter } from './router'
+
+export default createStartHandler({
+ createRouter,
+})(defaultStreamHandler)
+```
+
+The start handler is responsible for matching an incoming request to a server route and executing the appropriate middleware and handler.
+
+Remember, if you need to customize the server handler, you can do so by creating a custom handler and then passing the event to the start handler:
+
+```tsx
+// server.ts
+import { createStartHandler } from '@tanstack/react-start/server'
+
+export default defineHandler((event) => {
+ const startHandler = createStartHandler({
+ createRouter,
+ })(defaultStreamHandler)
+
+ return startHandler(event)
+})
+```
+
+## Defining an Server Route
+
+Server routes are created by exporting a `ServerRoute` from a route file. The `ServerRoute` export should be created by calling the `createServerFileRoute` function. The resulting builder object can then be used to:
+
+- Add route-level middleware
+- Define handlers for each HTTP method
+
+```ts
+// routes/hello.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return new Response('Hello, World! from ' + request.url)
+ },
+})
+```
+
+## Defining a Server Route Handler
+
+There are two ways to define a handler for a server route.
+
+- Provide a handler function directly to the method
+- By calling the `handler` method on the method builder object for more advanced use cases
+
+### Providing a handler function directly to the method
+
+For simple use cases, you can provide a handler function directly to the method.
+
+```ts
+// routes/hello.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return new Response('Hello, World! from ' + request.url)
+ },
+})
+```
+
+### Providing a handler function via the method builder object
+
+For more complex use cases, you can provide a handler function via the method builder object. This allows you to add middleware to the method.
+
+```tsx
+// routes/hello.ts
+export const ServerRoute = createServerFileRoute().methods((api) => ({
+ GET: api.middleware([loggerMiddleware]).handler(async ({ request }) => {
+ return new Response('Hello, World! from ' + request.url)
+ }),
+}))
+```
+
+## Handler Context
+
+Each HTTP method handler receives an object with the following properties:
+
+- `request`: The incoming request object. You can read more about the `Request` object in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Request).
+- `params`: An object containing the dynamic path parameters of the route. For example, if the route path is `/users/$id`, and the request is made to `/users/123`, then `params` will be `{ id: '123' }`. We'll cover dynamic path parameters and wildcard parameters later in this guide.
+- `context`: An object containing the context of the request. This is useful for passing data between middleware.
+
+Once you've processed the request, you can return a `Response` object or `Promise` or even use any of the helpers from `@tanstack/react-start` to manipulate the response.
+
+## Dynamic Path Params
+
+Server routes support dynamic path parameters in the same way as TanStack Router. For example, a file named `routes/users/$id.ts` will create an API route at `/users/$id` that accepts a dynamic `id` parameter.
+
+```ts
+// routes/users/$id.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ params }) => {
+ const { id } = params
+ return new Response(`User ID: ${id}`)
+ },
+})
+
+// Visit /api/users/123 to see the response
+// User ID: 123
+```
+
+You can also have multiple dynamic path parameters in a single route. For example, a file named `routes/users/$id/posts/$postId.ts` will create an API route at `/api/users/$id/posts/$postId` that accepts two dynamic parameters.
+
+```ts
+// routes/users/$id/posts/$postId.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ params }) => {
+ const { id, postId } = params
+ return new Response(`User ID: ${id}, Post ID: ${postId}`)
+ },
+})
+
+// Visit /api/users/123/posts/456 to see the response
+// User ID: 123, Post ID: 456
+```
+
+## Wildcard/Splat Param
+
+Server routes also support wildcard parameters at the end of the path, which are denoted by a `$` followed by nothing. For example, a file named `routes/file/$.ts` will create an API route at `/api/file/$` that accepts a wildcard parameter.
+
+```ts
+// routes/file/$.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ params }) => {
+ const { _splat } = params
+ return new Response(`File: ${_splat}`)
+ },
+})
+
+// Visit /api/file/hello.txt to see the response
+// File: hello.txt
+```
+
+## Handling requests with a body
+
+To handle POST requests,you can add a `POST` handler to the route object. The handler will receive the request object as the first argument, and you can access the request body using the `request.json()` method.
+
+```ts
+// routes/hello.ts
+export const ServerRoute = createServerFileRoute().methods({
+ POST: async ({ request }) => {
+ const body = await request.json()
+ return new Response(`Hello, ${body.name}!`)
+ },
+})
+
+// Send a POST request to /api/hello with a JSON body like { "name": "Tanner" }
+// Hello, Tanner!
+```
+
+This also applies to other HTTP methods like `PUT`, `PATCH`, and `DELETE`. You can add handlers for these methods in the route object and access the request body using the appropriate method.
+
+It's important to remember that the `request.json()` method returns a `Promise` that resolves to the parsed JSON body of the request. You need to `await` the result to access the body.
+
+This is a common pattern for handling POST requests in Server routes/ You can also use other methods like `request.text()` or `request.formData()` to access the body of the request.
+
+## Responding with JSON
+
+When returning JSON using a Response object, this is a common pattern:
+
+```ts
+// routes/hello.ts
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return new Response(JSON.stringify({ message: 'Hello, World!' }), {
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ })
+ },
+})
+
+// Visit /api/hello to see the response
+// {"message":"Hello, World!"}
+```
+
+## Using the `json` helper function
+
+Or you can use the `json` helper function to automatically set the `Content-Type` header to `application/json` and serialize the JSON object for you.
+
+```ts
+// routes/hello.ts
+import { json } from '@tanstack/react-start'
+
+export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return json({ message: 'Hello, World!' })
+ },
+})
+
+// Visit /api/hello to see the response
+// {"message":"Hello, World!"}
+```
+
+## Responding with a status code
+
+You can set the status code of the response by either:
+
+- Passing it as a property of the second argument to the `Response` constructor
+
+ ```ts
+ // routes/hello.ts
+ import { json } from '@tanstack/react-start'
+
+ export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request, params }) => {
+ const user = await findUser(params.id)
+ if (!user) {
+ return new Response('User not found', {
+ status: 404,
+ })
+ }
+ return json(user)
+ },
+ })
+ ```
+
+- Using the `setResponseStatus` helper function from `@tanstack/react-start/server`
+
+ ```ts
+ // routes/hello.ts
+ import { json } from '@tanstack/react-start'
+ import { setResponseStatus } from '@tanstack/react-start/server'
+
+ export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request, params }) => {
+ const user = await findUser(params.id)
+ if (!user) {
+ setResponseStatus(404)
+ return new Response('User not found')
+ }
+ return json(user)
+ },
+ })
+ ```
+
+In this example, we're returning a `404` status code if the user is not found. You can set any valid HTTP status code using this method.
+
+## Setting headers in the response
+
+Sometimes you may need to set headers in the response. You can do this by either:
+
+- Passing an object as the second argument to the `Response` constructor.
+
+ ```ts
+ // routes/hello.ts
+ export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ return new Response('Hello, World!', {
+ headers: {
+ 'Content-Type': 'text/plain',
+ },
+ })
+ },
+ })
+
+ // Visit /api/hello to see the response
+ // Hello, World!
+ ```
+
+- Or using the `setHeaders` helper function from `@tanstack/react-start/server`.
+
+ ```ts
+ // routes/hello.ts
+ import { setHeaders } from '@tanstack/react-start/server'
+
+ export const ServerRoute = createServerFileRoute().methods({
+ GET: async ({ request }) => {
+ setHeaders({
+ 'Content-Type': 'text/plain',
+ })
+ return new Response('Hello, World!')
+ },
+ })
+ ```
diff --git a/docs/start/framework/react/spa-mode.md b/docs/start/framework/react/spa-mode.md
new file mode 100644
index 0000000000..c2d5450c5b
--- /dev/null
+++ b/docs/start/framework/react/spa-mode.md
@@ -0,0 +1,188 @@
+---
+id: spa-mode
+title: SPA mode
+---
+
+## What the heck is SPA mode?
+
+For applications that do not require SSR for either SEO, crawlers, or performance reasons, it may be desirable to ship static HTML to your users containing the "shell" of your application (or even prerendered HTML for specific routes) that contain the necessary `html`, `head`, and `body` tags to bootstrap your application only on the client.
+
+## Why use Start without SSR?
+
+**No SSR doesn't mean giving up server-side features!** SPA modes actually pair very nicely with server-side features like server functions and/or server routes or even other external APIs. It **simply means that the initial document will not contain the fully rendered HTML of your application until it has been rendered on the client using JavaScript**.
+
+## Benefits of SPA mode
+
+- **Easier to deploy** - A CDN that can serve static assets is all you need.
+- **Cheaper** to host - CDNs are cheap compared to Lambda functions or long-running processes.
+- **Client-side Only is simpler** - No SSR means less to go wrong with hydration, rendering, and routing.
+
+## Caveats of SPA mode
+
+- **Slower time to full content** - Time to full content is longer since all JS must download and execute before anything below the shell can be rendered.
+- **Less SEO friendly** - Robots, crawlers and link unfurlers _may_ have a harder time indexing your application unless they are configured to execute JS and your application can render within a reasonable amount of time.
+
+## How does it work?
+
+After enabling the SPA mode, running a Start build will have an additional prerendering step afterwards to generate the shell. This is done by:
+
+- **Prerendering** your application's **root route only**
+- Where your application would normally render your matched routes, your router's configured **pending fallback component is rendered instead**.
+- The resulting HTML is stored to a static HTML page called `/_shell.html` (configurable)
+- Default rewrites are configured to redirect all 404 requests to the SPA mode shell
+
+> [!NOTE]
+> Other routes may also be prerendered and it is recommended to prerender as much as you can in SPA mode, but this is not required for SPA mode to work.
+
+## Configuring SPA mode
+
+To configure SPA mode, there are a few options you can add to your Start plugin's options:
+
+```tsx
+// vite.config.ts
+export default defineConfig({
+ plugins: [
+ TanStackStart({
+ spa: {
+ enabled: true,
+ },
+ }),
+ ],
+})
+```
+
+## Use Necessary Redirects
+
+Deploying a purely client-side SPA to a host or CDN often requires the use of redirects to ensure that urls are properly rewritten to the SPA shell. The goal of any deployment should include these priorities in this order:
+
+1. Ensure that static assets will always be served if they exist, e.g. /about.html. This is usually the default behavior for most CDNs
+2. (Optional) Allow-list specific subpaths to be routed through to any dynamic server handlers, e.g. /api/\*\* (More on this below)
+3. Ensure that all 404 requests are rewritten to the SPA shell, e.g. a catch-all redirect to /\_shell.html (or if you have configured your shell output path to be something custom, use that instead)
+
+## Basic Redirects Example
+
+Let's use Netlify's `_redirects` file to rewrite all 404 requests to the SPA shell.
+
+```
+# Catch all other 404 requests and rewrite them to the SPA shell
+/* /_shell.html 200
+```
+
+## Allowing Server Functions and Server Routes
+
+Again, using Netlify's `_redirects` file, we can allow-list specific subpaths to be routed through to the server.
+
+```
+# Allow requests to /_serverFn/* to be routed through to the server (If you have configured your server function base path to be something other than /_serverFn, use that instead)
+/_serverFn/* /_serverFn/:splat 200
+
+# Allow any requests to /api/* to be routed through to the server (Server routes can be created at any path, so you must ensure that any server routes you want to use are under this path, or simply add additional redirects for each server route base you want to expose)
+/api/* /api/:splat 200
+
+# Catch all other 404 requests and rewrite them to the SPA shell
+/* /_shell.html 200
+```
+
+## Shell Mask Path
+
+The default pathname used to generate the SPA shell is `/`. We call this the **shell mask path**. Since matched routes are not included, the pathname used to generate the shell is mostly irrelevant, but it's still configurable.
+
+> [!NOTE]
+> It's recommended to keep the default value of `/` as the shell mask path.
+
+```tsx
+// vite.config.ts
+export default defineConfig({
+ plugins: [
+ TanStackStart({
+ spa: {
+ maskPath: '/app',
+ },
+ }),
+ ],
+})
+```
+
+## Prerendering Options
+
+The prerender option is used to configure the prerendering behavior of the SPA shell, and accepts the same prerender options as found in our prerendering guide.
+
+**By default, the following `prerender` options are set:**
+
+- `outputPath`: `/_shell.html`
+- `crawlLinks`: `false`
+- `retryCount`: `0`
+
+This means that by default, the shell will not be crawled for links to follow for additional prerendering, and will not retry prerendering fails.
+
+You can always override these options by providing your own prerender options:
+
+```tsx
+// vite.config.ts
+export default defineConfig({
+ plugins: [
+ TanStackStart({
+ spa: {
+ prerender: {
+ outputPath: '/custom-shell',
+ crawlLinks: true,
+ retryCount: 3,
+ },
+ },
+ }),
+ ],
+})
+```
+
+## Customized rendering in SPA mode
+
+Customizing the HTML output of the SPA shell can be useful if you want to:
+
+- Provide generic head tags for SPA routes
+- Provide a custom pending fallback component
+- Change literally anything about the shell's HTML, CSS, and JS
+
+To make this process simple, an `isShell` boolean can be found on the `router` instance:
+
+```tsx
+// src/routes/root.tsx
+export default function Root() {
+ const isShell = useRouter().isShell
+
+ if (isShell) console.log('Rendering the shell!')
+}
+```
+
+You can use this boolean to conditionally render different UI based on whether the current route is a shell or not, but keep in mind that after hydrating the shell, the router will immediately navigate to the first route and the `isShell` boolean will be `false`. **This could produce flashes of unstyled content if not handled properly.**
+
+## Dynamic Data in your Shell
+
+Since the shell is prerendered using the SSR build of your application, any `loader`s, or server-specific functionality defined on your **Root Route** will run during the prerendering process and the data will be included in the shell.
+
+This means that you can use dynamic data in your shell by using a `loader` or server-specific functionality.
+
+```tsx
+// src/routes/__root.tsx
+
+export const RootRoute = createRootRoute({
+ loader: async () => {
+ return {
+ name: 'Tanner',
+ }
+ },
+ component: Root,
+})
+
+export default function Root() {
+ const { name } = useLoaderData()
+
+ return (
+
+
+
Hello, {name}!
+
+
+
+ )
+}
+```
diff --git a/docs/start/framework/react/ssr.md b/docs/start/framework/react/ssr.md
deleted file mode 100644
index f509d47f72..0000000000
--- a/docs/start/framework/react/ssr.md
+++ /dev/null
@@ -1,34 +0,0 @@
----
-id: ssr
-title: SSR
----
-
-Server-side rendering (SSR) is the process of rendering your application on the server and sending or streaming the rendered HTML to the client. This can be useful for both improving the performance of your application and improving SEO, as it allows users to see the content of your application faster and allows search engines to crawl your application more easily.
-
-## SSR Basics
-
-TanStack Start supports server-side rendering out of the box. To enable server-side rendering, create an `app/ssr.tsx` file in your project:
-
-```tsx
-// app/ssr.tsx
-
-import {
- createStartHandler,
- defaultStreamHandler,
-} from '@tanstack/react-start/server'
-import { getRouterManifest } from '@tanstack/react-start/router-manifest'
-
-import { createRouter } from './router'
-
-export default createStartHandler({
- createRouter,
- getRouterManifest,
-})(defaultStreamHandler)
-```
-
-This file exports a function that creates a server-side rendering handler. The handler is created using the `createStartHandler` function from `@tanstack/react-start/server`, which takes an object with the following properties:
-
-- `createRouter`: A function that creates a router for your application. This function should return a new router instance each time it is called.
-- `getRouterManifest`: A function that returns a manifest of all the routes in your application.
-
-The handler is then called with the `defaultStreamHandler` function from `@tanstack/react-start/server`, which is a function that streams the response to the client.
diff --git a/docs/start/framework/react/static-prerendering.md b/docs/start/framework/react/static-prerendering.md
index 768e11d539..30111f24fb 100644
--- a/docs/start/framework/react/static-prerendering.md
+++ b/docs/start/framework/react/static-prerendering.md
@@ -3,13 +3,11 @@ id: static-prerendering
title: Static Prerendering
---
-> Static Prerendering is a feature of Nitro, and while it is available in TanStack Start, we are still exploring the best practices for using it. Tread lightly!
-
Static prerendering is the process of generating static HTML files for your application. This can be useful for either improving the performance of your application, as it allows you to serve pre-rendered HTML files to users without having to generate them on the fly or for deploying static sites to platforms that do not support server-side rendering.
-## Prerendering, powered by Nitro
+## Prerendering
-TanStack Start is built on Nitro, which means we can take advantage of Nitro's prerendering capabilities. Nitro can prerender your application to static HTML files, which can then be served to users without having to generate them on the fly. To prerender your application, you can add the `server.prerender` option to your `app.config.js` file:
+TanStack Start can prerender your application to static HTML files, which can then be served to users without having to generate them on the fly. To prerender your application, you can add the `server.prerender` option to your `app.config.js` file:
```js
// app.config.js
@@ -25,39 +23,3 @@ export default defineConfig({
},
})
```
-
-Many of the options available for prerendering are documented in the [Nitro config prerender documentation](https://nitro.unjs.io/config#prerender).
-
-## Prerendering dynamic routes with Nitro
-
-Nitro ships with some prebuilt hooks that let you customize the prerendering process among other things. One of these hooks is the `prerender:routes` hook. This hook allows you to fetch async data and add routes to a `Set` of routes to be prerendered.
-
-For this example, let's pretend we have a blog with a list of posts. We want to prerender each post page. Our post route looks like `/posts/$postId`. We can use the `prerender:routes` hook to fetch the all of our posts and add each post path to the routes set.
-
-```ts
-// app.config.ts
-import { defineConfig } from '@tanstack/react-start/config'
-
-export default defineConfig({
- server: {
- hooks: {
- 'prerender:routes': async (routes) => {
- // fetch the pages you want to render
- const posts = await fetch('https://api.example.com/posts')
- const postsData = await posts.json()
-
- // add each post path to the routes set
- postsData.forEach((post) => {
- routes.add(`/posts/${post.id}`)
- })
- },
- },
- prerender: {
- routes: ['/'],
- crawlLinks: true,
- },
- },
-})
-```
-
-As of writing, the [Nitro hooks documentation](https://nitro.build/config#hooks) does not include any information on the provided hooks.
diff --git a/docs/start/framework/solid/api-routes.md b/docs/start/framework/solid/api-routes.md
deleted file mode 100644
index fcc7ab4613..0000000000
--- a/docs/start/framework/solid/api-routes.md
+++ /dev/null
@@ -1,4 +0,0 @@
----
-ref: docs/start/framework/react/api-routes.md
-replace: { 'react': 'solid' }
----
diff --git a/docs/start/framework/solid/authentication.md b/docs/start/framework/solid/authentication.md
index 24a74f7316..eee03da9da 100644
--- a/docs/start/framework/solid/authentication.md
+++ b/docs/start/framework/solid/authentication.md
@@ -17,9 +17,9 @@ That said, authentication is not something to be taken lightly. After much vetti
-
-
-
+
+
+
diff --git a/docs/start/framework/solid/build-from-scratch.md b/docs/start/framework/solid/build-from-scratch.md
index c5fcdb3563..4549c6f0ba 100644
--- a/docs/start/framework/solid/build-from-scratch.md
+++ b/docs/start/framework/solid/build-from-scratch.md
@@ -4,7 +4,7 @@ title: Build a Project from Scratch
---
> [!NOTE]
-> If you chose to quick start with an example or cloned project, you can skip this guide and move on to the [Learn the Basics](../learn-the-basics) guide.
+> If you chose to quick start with an example or cloned project, you can skip this guide and move on to the [Learn the Basics](./learn-the-basics.md) guide.
_So you want to build a TanStack Start project from scratch?_
@@ -48,85 +48,75 @@ We highly recommend using TypeScript with TanStack Start. Create a `tsconfig.jso
## Install Dependencies
-TanStack Start is (currently\*) powered by [Vinxi](https://vinxi.vercel.app/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
-
-> [!NOTE] > \*Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin or dedicated TanStack Start CLI.
+TanStack Start is powered by [Vite](https://vite.dev/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
To install them, run:
```shell
-npm i @tanstack/solid-start @tanstack/solid-router vinxi
+npm i @tanstack/solid-start @tanstack/solid-router vite
```
-You'll also need Solid and the Vite Solid plugin, so install them too:
+You'll also need Solid:
```shell
npm i solid-js
-npm i -D vite-plugin-solid vite-tsconfig-paths
```
and some TypeScript:
```shell
-npm i -D typescript
+npm i -D typescript vite-tsconfig-paths
```
## Update Configuration Files
-We'll then update our `package.json` to use Vinxi's CLI and set `"type": "module"`:
+We'll then update our `package.json` to use Vite's CLI and set `"type": "module"`:
```json
{
// ...
"type": "module",
"scripts": {
- "dev": "vinxi dev",
- "build": "vinxi build",
- "start": "vinxi start"
+ "dev": "vite dev",
+ "build": "vite build"
}
}
```
-Then configure TanStack Start's `app.config.ts` file:
+Then configure TanStack Start's Vite plugin in `vite.config.ts`:
-```typescript
-// app.config.ts
-import { defineConfig } from '@tanstack/solid-start/config'
+```ts
+// vite.config.ts
+import { defineConfig } from 'vite'
import tsConfigPaths from 'vite-tsconfig-paths'
+import { tanstackStart } from '@tanstack/solid-start/plugin/vite'
export default defineConfig({
- vite: {
- plugins: [
- tsConfigPaths({
- projects: ['./tsconfig.json'],
- }),
- ],
+ server: {
+ port: 3000,
},
+ plugins: [tsConfigPaths(), tanstackStart()],
})
```
## Add the Basic Templating
-There are four required files for TanStack Start usage:
+There are 2 required files for TanStack Start usage:
1. The router configuration
-2. The server entry point
-3. The client entry point
-4. The root of your application
+2. The root of your application
Once configuration is done, we'll have a file tree that looks like the following:
```
.
-├── app/
+├── src/
│ ├── routes/
│ │ └── `__root.tsx`
-│ ├── `client.tsx`
│ ├── `router.tsx`
│ ├── `routeTree.gen.ts`
-│ └── `ssr.tsx`
├── `.gitignore`
-├── `app.config.ts`
+├── `vite.config.ts`
├── `package.json`
└── `tsconfig.json`
```
@@ -140,7 +130,7 @@ from the default [preloading functionality](/router/latest/docs/framework/solid/
> You won't have a `routeTree.gen.ts` file yet. This file will be generated when you run TanStack Start for the first time.
```tsx
-// app/router.tsx
+// src/router.tsx
import { createRouter as createTanStackRouter } from '@tanstack/solid-router'
import { routeTree } from './routeTree.gen'
@@ -160,54 +150,15 @@ declare module '@tanstack/solid-router' {
}
```
-## The Server Entry Point
-
-As TanStack Start is an [SSR](https://unicorn-utterances.com/posts/what-is-ssr-and-ssg) framework, we need to pipe this router
-information to our server entry point:
-
-```tsx
-// app/ssr.tsx
-import {
- createStartHandler,
- defaultStreamHandler,
-} from '@tanstack/solid-start/server'
-import { getRouterManifest } from '@tanstack/solid-start/router-manifest'
-
-import { createRouter } from './router'
-
-export default createStartHandler({
- createRouter,
- getRouterManifest,
-})(defaultStreamHandler)
-```
-
-This allows us to know what routes and loaders we need to execute when the user hits a given route.
-
-## The Client Entry Point
-
-Now we need a way to hydrate our client-side JavaScript once the route resolves to the client. We do this by piping the same
-router information to our client entry point:
-
-```tsx
-// app/client.tsx
-///
-import { hydrate } from 'solid-js/web'
-import { StartClient } from '@tanstack/solid-start'
-import { createRouter } from './router'
-
-const router = createRouter()
-
-hydrate(() => , document.body)
-```
-
-This enables us to kick off client-side routing once the user's initial server request has fulfilled.
+> [!NOTE]
+> TanStack Start provides **default server and client entry points** to handle requests and client-entry + hydration. You can customize these entry points by adding a `server.ts` and/or `client.tsx` file in the root of your project, but for now, we'll use the defaults.
## The Root of Your Application
Finally, we need to create the root of our application. This is the entry point for all other routes. The code in this file will wrap all other routes in the application.
```tsx
-// app/routes/__root.tsx
+// src/routes/__root.tsx
import {
Outlet,
createRootRoute,
@@ -243,9 +194,9 @@ function RootComponent() {
Now that we have the basic templating setup, we can write our first route. This is done by creating a new file in the `app/routes` directory.
```tsx
-// app/routes/index.tsx
+// src/routes/index.tsx
import * as fs from 'node:fs'
-import { createFileRoute, useRouter } from '@tanstack/solid-router'
+import { useRouter } from '@tanstack/solid-router'
import { createServerFn } from '@tanstack/solid-start'
const filePath = 'count.txt'
@@ -269,7 +220,7 @@ const updateCount = createServerFn({ method: 'POST' })
await fs.promises.writeFile(filePath, `${count + data}`)
})
-export const Route = createFileRoute('/')({
+export const Route = createFileRoute({
component: Home,
loader: async () => await getCount(),
})
diff --git a/docs/start/framework/solid/hosting.md b/docs/start/framework/solid/hosting.md
index 0acb872b8b..0a1586223e 100644
--- a/docs/start/framework/solid/hosting.md
+++ b/docs/start/framework/solid/hosting.md
@@ -15,9 +15,9 @@ However, since hosting is one of the most crucial aspects of your application's
-
-
-
+
+
+
diff --git a/docs/start/framework/solid/learn-the-basics.md b/docs/start/framework/solid/learn-the-basics.md
index 094b965623..a7a7d2c545 100644
--- a/docs/start/framework/solid/learn-the-basics.md
+++ b/docs/start/framework/solid/learn-the-basics.md
@@ -7,13 +7,10 @@ This guide will help you learn the basics behind how TanStack Start works, regar
## Dependencies
-TanStack Start is (currently\*) powered by [Vinxi](https://vinxi.vercel.app/), [Nitro](https://nitro.unjs.io/) and [TanStack Router](https://tanstack.com/router).
+TanStack Start is powered by [Vite](https://vite.dev/) and [TanStack Router](https://tanstack.com/router).
- **TanStack Router**: A router for building web applications.
-- **Nitro**: A framework for building server applications.
-- **Vinxi**: A server framework for building web applications.
-
-> [!NOTE] Vinxi will be removed before version 1.0.0 is released and TanStack will rely only on Vite and Nitro. The commands and APIs that use Vinxi will likely be replaced with a Vite plugin.
+- **Vite**: A build tool for bundling your application.
## It all "Starts" with the Router
@@ -47,41 +44,41 @@ declare module '@tanstack/solid-router' {
The `routeTree.gen.ts` file is generated when you run TanStack Start (via `npm run dev` or `npm run start`) for the first time. This file contains the generated route tree and a handful of TS utilities that make TanStack Start fully type-safe.
-## The Server Entry Point
+## The Server Entry Point (Optional)
-Although TanStack Start is designed with client-first APIs, it is by and large, a full-stack framework. This means that all use cases, including both dynamic and static rely on a server or build-time entry to render our application's initial HTML payload.
+> [!NOTE]
+> The server entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the server entry point for you using the below as a default.
-This is done via the `app/ssr.tsx` file:
+This is done via the `src/server.ts` file:
```tsx
-// app/ssr.tsx
+// src/server.ts
import {
createStartHandler,
defaultStreamHandler,
} from '@tanstack/solid-start/server'
-import { getRouterManifest } from '@tanstack/solid-start/router-manifest'
import { createRouter } from './router'
export default createStartHandler({
createRouter,
- getRouterManifest,
})(defaultStreamHandler)
```
-Whether we are statically generating our app or serving it dynamically, the `ssr.tsx` file is the entry point for doing all SSR-related work.
+Whether we are statically generating our app or serving it dynamically, the `server.ts` file is the entry point for doing all SSR-related work.
- It's important that a new router is created for each request. This ensures that any data handled by the router is unique to the request.
-- The `getRouterManifest` function is used to generate the router manifest, which is used to determine many aspects of asset management and preloading for our application.
- The `defaultStreamHandler` function is used to render our application to a stream, allowing us to take advantage of streaming HTML to the client. (This is the default handler, but you can also use other handlers like `defaultRenderHandler`, or even build your own)
-## The Client Entry Point
+## The Client Entry Point (Optional)
+
+> [!NOTE]
+> The client entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the client entry point for you using the below as a default.
Getting our html to the client is only half the battle. Once there, we need to hydrate our client-side JavaScript once the route resolves to the client. We do this by hydrating the root of our application with the `StartClient` component:
```tsx
// app/client.tsx
-///
import { hydrate } from 'solid-js/web'
import { StartClient } from '@tanstack/solid-start'
import { createRouter } from './router'
@@ -95,7 +92,7 @@ This enables us to kick off client-side routing once the user's initial server r
## The Root of Your Application
-Other than the client entry point, the `__root` route of your application is the entry point for your application. The code in this file will wrap all other routes in the app, including your home page. It behaves like a pathless layout route for your whole application.
+Other than the client entry point (which is optional by default), the `__root` route of your application is the entry point for your application. The code in this file will wrap all other routes in the app, including your home page. It behaves like a pathless layout route for your whole application.
Because it is **always rendered**, it is the perfect place to construct your application shell and take care of any global logic.
diff --git a/docs/start/framework/solid/server-routes.md b/docs/start/framework/solid/server-routes.md
new file mode 100644
index 0000000000..9fe19933d0
--- /dev/null
+++ b/docs/start/framework/solid/server-routes.md
@@ -0,0 +1,4 @@
+---
+ref: docs/start/framework/react/server-routes.md
+replace: { 'react': 'solid' }
+---
diff --git a/docs/start/framework/solid/spa-mode.md b/docs/start/framework/solid/spa-mode.md
new file mode 100644
index 0000000000..0124b857d2
--- /dev/null
+++ b/docs/start/framework/solid/spa-mode.md
@@ -0,0 +1,3 @@
+---
+ref: docs/start/framework/react/spa-mode.md
+---
diff --git a/docs/start/framework/solid/ssr.md b/docs/start/framework/solid/ssr.md
deleted file mode 100644
index c99a3d9280..0000000000
--- a/docs/start/framework/solid/ssr.md
+++ /dev/null
@@ -1,4 +0,0 @@
----
-ref: docs/start/framework/react/ssr.md
-replace: { 'react': 'solid' }
----
diff --git a/e2e/create-start/.gitignore b/e2e/create-start/.gitignore
deleted file mode 100644
index 8354e4d50d..0000000000
--- a/e2e/create-start/.gitignore
+++ /dev/null
@@ -1,10 +0,0 @@
-node_modules
-.DS_Store
-dist
-dist-ssr
-*.local
-
-/test-results/
-/playwright-report/
-/blob-report/
-/playwright/.cache/
\ No newline at end of file
diff --git a/e2e/create-start/package.json b/e2e/create-start/package.json
deleted file mode 100644
index 1c46410866..0000000000
--- a/e2e/create-start/package.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "create-start-e2e",
- "private": true,
- "type": "module",
- "scripts": {
- "test:e2e": "playwright test --project=chromium"
- },
- "devDependencies": {
- "@playwright/test": "^1.50.1",
- "@tanstack/create-start": "workspace:^",
- "get-port-please": "^3.1.2",
- "tempy": "^3.1.0",
- "terminate": "^2.8.0",
- "wait-port": "^1.1.0"
- }
-}
diff --git a/e2e/create-start/playwright.config.ts b/e2e/create-start/playwright.config.ts
deleted file mode 100644
index b07c8b268b..0000000000
--- a/e2e/create-start/playwright.config.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { defineConfig, devices } from '@playwright/test'
-
-/**
- * See https://playwright.dev/docs/test-configuration.
- */
-export default defineConfig({
- testDir: './tests',
-
- reporter: [['line']],
- timeout: 60000,
- use: {
- trace: 'on-first-retry',
- },
- workers: 1,
-
- // use: {
- // /* Base URL to use in actions like `await page.goto('/')`. */
- // baseURL: 'http://localhost:3001/',
- // },
-
- // webServer: {
- // command: 'pnpm run dev',
- // url: 'http://localhost:3001',
- // reuseExistingServer: !process.env.CI,
- // stdout: 'pipe',
- // },
-
- projects: [
- {
- name: 'chromium',
- use: { ...devices['Desktop Chrome'] },
- },
- ],
-})
diff --git a/e2e/create-start/tests/templates/barebones.test.ts b/e2e/create-start/tests/templates/barebones.test.ts
deleted file mode 100644
index 8778ef37d7..0000000000
--- a/e2e/create-start/tests/templates/barebones.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { temporaryDirectory } from 'tempy'
-import { getRandomPort } from 'get-port-please'
-import { unstable_scaffoldTemplate } from '@tanstack/create-start'
-import { test } from '../../utils/setup'
-
-// Before running any tests - create the project in the temporary directory
-const projectPath = temporaryDirectory()
-await unstable_scaffoldTemplate({
- cfg: {
- packageManager: {
- installDeps: true,
- packageManager: 'pnpm',
- },
- git: {
- setupGit: false,
- },
- packageJson: {
- type: 'new',
- name: 'barebones-test',
- },
- ide: {
- ide: 'vscode',
- },
- },
- targetPath: projectPath,
- templateId: 'barebones',
-})
-
-const PORT = await getRandomPort()
-test.use({ projectPath })
-test.use({ port: PORT })
-test.use({ baseURL: `http://localhost:${PORT}` })
-
-test.describe('barebones template e2e', () => {
- test('Navigating to index page', async ({ page }) => {
- await page.goto('/')
- })
-})
diff --git a/e2e/create-start/tsconfig.json b/e2e/create-start/tsconfig.json
deleted file mode 100644
index 44c53edd67..0000000000
--- a/e2e/create-start/tsconfig.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "compilerOptions": {
- "strict": true,
- "esModuleInterop": true,
- "jsx": "react-jsx",
- "target": "ESNext",
- "moduleResolution": "Bundler",
- "module": "ESNext",
- "skipLibCheck": true
- }
-}
diff --git a/e2e/create-start/utils/setup.ts b/e2e/create-start/utils/setup.ts
deleted file mode 100644
index bfb4c1fd53..0000000000
--- a/e2e/create-start/utils/setup.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { exec, execSync } from 'node:child_process'
-import { test as baseTest } from '@playwright/test'
-import terminate from 'terminate/promise'
-import waitPort from 'wait-port'
-
-async function _setup(
- projectPath: string,
- port: number,
-): Promise<{
- PID: number
- ADDR: string
- killProcess: () => Promise
- deleteTempDir: () => void
-}> {
- const ADDR = `http://localhost:${port}`
-
- const childProcess = exec(
- `VITE_SERVER_PORT=${port} pnpm vinxi dev --port ${port}`,
- {
- cwd: projectPath,
- },
- )
-
- childProcess.stdout?.on('data', (data) => {
- const message = data.toString()
- console.log('Stdout:', message)
- })
-
- childProcess.stderr?.on('data', (data) => {
- console.error('Stderr:', data.toString())
- })
-
- try {
- await waitPort({ port, timeout: 30000 }) // Added timeout
- } catch (err) {
- console.error('Failed to start server:', err)
- throw err
- }
-
- const PID = childProcess.pid!
- const killProcess = async () => {
- console.log('Killing process')
- try {
- await terminate(PID)
- } catch (err) {
- console.error('Failed to kill process:', err)
- }
- }
- const deleteTempDir = () => execSync(`rm -rf ${projectPath}`)
-
- return { PID, ADDR, killProcess, deleteTempDir }
-}
-
-type SetupApp = Awaited>
-
-export const test = baseTest.extend<{
- setupApp: SetupApp
- projectPath: string
- port: number
- ensureServer: void
-}>({
- projectPath: ['', { option: true }],
- port: [0, { option: true }],
- ensureServer: [
- async ({ projectPath, port }, use) => {
- const setup = await _setup(projectPath, port)
- await use()
- await setup.killProcess()
- },
- { auto: true },
- ],
-})
diff --git a/e2e/react-router/basic-esbuild-file-based/src/esbuild.config.js b/e2e/react-router/basic-esbuild-file-based/src/esbuild.config.js
index 9deed8a53d..5f0f4fce03 100644
--- a/e2e/react-router/basic-esbuild-file-based/src/esbuild.config.js
+++ b/e2e/react-router/basic-esbuild-file-based/src/esbuild.config.js
@@ -1,9 +1,9 @@
-import { TanStackRouterEsbuild } from '@tanstack/router-plugin/esbuild'
+import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
export default {
// ...
plugins: [
- TanStackRouterEsbuild({
+ tanstackRouter({
autoCodeSplitting: true,
}),
],
diff --git a/e2e/react-router/basic-file-based-code-splitting/package.json b/e2e/react-router/basic-file-based-code-splitting/package.json
index d3cd1e2425..38efb81ef7 100644
--- a/e2e/react-router/basic-file-based-code-splitting/package.json
+++ b/e2e/react-router/basic-file-based-code-splitting/package.json
@@ -27,6 +27,6 @@
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-react": "^4.3.4",
- "vite": "^6.1.0"
+ "vite": "^6.3.5"
}
}
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts b/e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts
index 12e3efedb5..4ff69b1e7d 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routeTree.gen.ts
@@ -8,75 +8,77 @@
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
+import type { CreateFileRoute, FileRoutesByPath } from '@tanstack/react-router'
+
// Import Routes
import { Route as rootRoute } from './routes/__root'
-import { Route as WithoutLoaderImport } from './routes/without-loader'
-import { Route as ViewportTestImport } from './routes/viewport-test'
-import { Route as PostsImport } from './routes/posts'
-import { Route as LayoutImport } from './routes/_layout'
-import { Route as IndexImport } from './routes/index'
-import { Route as PostsIndexImport } from './routes/posts.index'
-import { Route as PostsPostIdImport } from './routes/posts.$postId'
-import { Route as LayoutLayout2Import } from './routes/_layout/_layout-2'
-import { Route as LayoutLayout2LayoutBImport } from './routes/_layout/_layout-2/layout-b'
-import { Route as LayoutLayout2LayoutAImport } from './routes/_layout/_layout-2/layout-a'
+import { Route as WithoutLoaderRouteImport } from './routes/without-loader'
+import { Route as ViewportTestRouteImport } from './routes/viewport-test'
+import { Route as PostsRouteImport } from './routes/posts'
+import { Route as LayoutRouteImport } from './routes/_layout'
+import { Route as IndexRouteImport } from './routes/index'
+import { Route as PostsIndexRouteImport } from './routes/posts.index'
+import { Route as PostsPostIdRouteImport } from './routes/posts.$postId'
+import { Route as LayoutLayout2RouteImport } from './routes/_layout/_layout-2'
+import { Route as LayoutLayout2LayoutBRouteImport } from './routes/_layout/_layout-2/layout-b'
+import { Route as LayoutLayout2LayoutARouteImport } from './routes/_layout/_layout-2/layout-a'
// Create/Update Routes
-const WithoutLoaderRoute = WithoutLoaderImport.update({
+const WithoutLoaderRoute = WithoutLoaderRouteImport.update({
id: '/without-loader',
path: '/without-loader',
getParentRoute: () => rootRoute,
} as any)
-const ViewportTestRoute = ViewportTestImport.update({
+const ViewportTestRoute = ViewportTestRouteImport.update({
id: '/viewport-test',
path: '/viewport-test',
getParentRoute: () => rootRoute,
} as any)
-const PostsRoute = PostsImport.update({
+const PostsRoute = PostsRouteImport.update({
id: '/posts',
path: '/posts',
getParentRoute: () => rootRoute,
} as any)
-const LayoutRoute = LayoutImport.update({
+const LayoutRoute = LayoutRouteImport.update({
id: '/_layout',
getParentRoute: () => rootRoute,
} as any)
-const IndexRoute = IndexImport.update({
+const IndexRoute = IndexRouteImport.update({
id: '/',
path: '/',
getParentRoute: () => rootRoute,
} as any)
-const PostsIndexRoute = PostsIndexImport.update({
+const PostsIndexRoute = PostsIndexRouteImport.update({
id: '/',
path: '/',
getParentRoute: () => PostsRoute,
} as any)
-const PostsPostIdRoute = PostsPostIdImport.update({
+const PostsPostIdRoute = PostsPostIdRouteImport.update({
id: '/$postId',
path: '/$postId',
getParentRoute: () => PostsRoute,
} as any)
-const LayoutLayout2Route = LayoutLayout2Import.update({
+const LayoutLayout2Route = LayoutLayout2RouteImport.update({
id: '/_layout-2',
getParentRoute: () => LayoutRoute,
} as any)
-const LayoutLayout2LayoutBRoute = LayoutLayout2LayoutBImport.update({
+const LayoutLayout2LayoutBRoute = LayoutLayout2LayoutBRouteImport.update({
id: '/layout-b',
path: '/layout-b',
getParentRoute: () => LayoutLayout2Route,
} as any)
-const LayoutLayout2LayoutARoute = LayoutLayout2LayoutAImport.update({
+const LayoutLayout2LayoutARoute = LayoutLayout2LayoutARouteImport.update({
id: '/layout-a',
path: '/layout-a',
getParentRoute: () => LayoutLayout2Route,
@@ -90,75 +92,168 @@ declare module '@tanstack/react-router' {
id: '/'
path: '/'
fullPath: '/'
- preLoaderRoute: typeof IndexImport
+ preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRoute
}
'/_layout': {
id: '/_layout'
path: ''
fullPath: ''
- preLoaderRoute: typeof LayoutImport
+ preLoaderRoute: typeof LayoutRouteImport
parentRoute: typeof rootRoute
}
'/posts': {
id: '/posts'
path: '/posts'
fullPath: '/posts'
- preLoaderRoute: typeof PostsImport
+ preLoaderRoute: typeof PostsRouteImport
parentRoute: typeof rootRoute
}
'/viewport-test': {
id: '/viewport-test'
path: '/viewport-test'
fullPath: '/viewport-test'
- preLoaderRoute: typeof ViewportTestImport
+ preLoaderRoute: typeof ViewportTestRouteImport
parentRoute: typeof rootRoute
}
'/without-loader': {
id: '/without-loader'
path: '/without-loader'
fullPath: '/without-loader'
- preLoaderRoute: typeof WithoutLoaderImport
+ preLoaderRoute: typeof WithoutLoaderRouteImport
parentRoute: typeof rootRoute
}
'/_layout/_layout-2': {
id: '/_layout/_layout-2'
path: ''
fullPath: ''
- preLoaderRoute: typeof LayoutLayout2Import
- parentRoute: typeof LayoutImport
+ preLoaderRoute: typeof LayoutLayout2RouteImport
+ parentRoute: typeof LayoutRouteImport
}
'/posts/$postId': {
id: '/posts/$postId'
path: '/$postId'
fullPath: '/posts/$postId'
- preLoaderRoute: typeof PostsPostIdImport
- parentRoute: typeof PostsImport
+ preLoaderRoute: typeof PostsPostIdRouteImport
+ parentRoute: typeof PostsRouteImport
}
'/posts/': {
id: '/posts/'
path: '/'
fullPath: '/posts/'
- preLoaderRoute: typeof PostsIndexImport
- parentRoute: typeof PostsImport
+ preLoaderRoute: typeof PostsIndexRouteImport
+ parentRoute: typeof PostsRouteImport
}
'/_layout/_layout-2/layout-a': {
id: '/_layout/_layout-2/layout-a'
path: '/layout-a'
fullPath: '/layout-a'
- preLoaderRoute: typeof LayoutLayout2LayoutAImport
- parentRoute: typeof LayoutLayout2Import
+ preLoaderRoute: typeof LayoutLayout2LayoutARouteImport
+ parentRoute: typeof LayoutLayout2RouteImport
}
'/_layout/_layout-2/layout-b': {
id: '/_layout/_layout-2/layout-b'
path: '/layout-b'
fullPath: '/layout-b'
- preLoaderRoute: typeof LayoutLayout2LayoutBImport
- parentRoute: typeof LayoutLayout2Import
+ preLoaderRoute: typeof LayoutLayout2LayoutBRouteImport
+ parentRoute: typeof LayoutLayout2RouteImport
}
}
}
+// Add type-safety to the createFileRoute function across the route tree
+
+declare module './routes/index' {
+ const createFileRoute: CreateFileRoute<
+ '/',
+ FileRoutesByPath['/']['parentRoute'],
+ FileRoutesByPath['/']['id'],
+ FileRoutesByPath['/']['path'],
+ FileRoutesByPath['/']['fullPath']
+ >
+}
+declare module './routes/_layout' {
+ const createFileRoute: CreateFileRoute<
+ '/_layout',
+ FileRoutesByPath['/_layout']['parentRoute'],
+ FileRoutesByPath['/_layout']['id'],
+ FileRoutesByPath['/_layout']['path'],
+ FileRoutesByPath['/_layout']['fullPath']
+ >
+}
+declare module './routes/posts' {
+ const createFileRoute: CreateFileRoute<
+ '/posts',
+ FileRoutesByPath['/posts']['parentRoute'],
+ FileRoutesByPath['/posts']['id'],
+ FileRoutesByPath['/posts']['path'],
+ FileRoutesByPath['/posts']['fullPath']
+ >
+}
+declare module './routes/viewport-test' {
+ const createFileRoute: CreateFileRoute<
+ '/viewport-test',
+ FileRoutesByPath['/viewport-test']['parentRoute'],
+ FileRoutesByPath['/viewport-test']['id'],
+ FileRoutesByPath['/viewport-test']['path'],
+ FileRoutesByPath['/viewport-test']['fullPath']
+ >
+}
+declare module './routes/without-loader' {
+ const createFileRoute: CreateFileRoute<
+ '/without-loader',
+ FileRoutesByPath['/without-loader']['parentRoute'],
+ FileRoutesByPath['/without-loader']['id'],
+ FileRoutesByPath['/without-loader']['path'],
+ FileRoutesByPath['/without-loader']['fullPath']
+ >
+}
+declare module './routes/_layout/_layout-2' {
+ const createFileRoute: CreateFileRoute<
+ '/_layout/_layout-2',
+ FileRoutesByPath['/_layout/_layout-2']['parentRoute'],
+ FileRoutesByPath['/_layout/_layout-2']['id'],
+ FileRoutesByPath['/_layout/_layout-2']['path'],
+ FileRoutesByPath['/_layout/_layout-2']['fullPath']
+ >
+}
+declare module './routes/posts.$postId' {
+ const createFileRoute: CreateFileRoute<
+ '/posts/$postId',
+ FileRoutesByPath['/posts/$postId']['parentRoute'],
+ FileRoutesByPath['/posts/$postId']['id'],
+ FileRoutesByPath['/posts/$postId']['path'],
+ FileRoutesByPath['/posts/$postId']['fullPath']
+ >
+}
+declare module './routes/posts.index' {
+ const createFileRoute: CreateFileRoute<
+ '/posts/',
+ FileRoutesByPath['/posts/']['parentRoute'],
+ FileRoutesByPath['/posts/']['id'],
+ FileRoutesByPath['/posts/']['path'],
+ FileRoutesByPath['/posts/']['fullPath']
+ >
+}
+declare module './routes/_layout/_layout-2/layout-a' {
+ const createFileRoute: CreateFileRoute<
+ '/_layout/_layout-2/layout-a',
+ FileRoutesByPath['/_layout/_layout-2/layout-a']['parentRoute'],
+ FileRoutesByPath['/_layout/_layout-2/layout-a']['id'],
+ FileRoutesByPath['/_layout/_layout-2/layout-a']['path'],
+ FileRoutesByPath['/_layout/_layout-2/layout-a']['fullPath']
+ >
+}
+declare module './routes/_layout/_layout-2/layout-b' {
+ const createFileRoute: CreateFileRoute<
+ '/_layout/_layout-2/layout-b',
+ FileRoutesByPath['/_layout/_layout-2/layout-b']['parentRoute'],
+ FileRoutesByPath['/_layout/_layout-2/layout-b']['id'],
+ FileRoutesByPath['/_layout/_layout-2/layout-b']['path'],
+ FileRoutesByPath['/_layout/_layout-2/layout-b']['fullPath']
+ >
+}
+
// Create and export the route tree
interface LayoutLayout2RouteChildren {
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout.tsx
index 02ddbb1cd9..5c4a461d8d 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout.tsx
@@ -1,6 +1,6 @@
-import { Outlet, createFileRoute } from '@tanstack/react-router'
+import { Outlet } from '@tanstack/react-router'
-export const Route = createFileRoute('/_layout')({
+export const Route = createFileRoute({
component: LayoutComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2.tsx
index 3b7dbf2903..483b910862 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2.tsx
@@ -1,6 +1,6 @@
-import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
+import { Link, Outlet } from '@tanstack/react-router'
-export const Route = createFileRoute('/_layout/_layout-2')({
+export const Route = createFileRoute({
component: LayoutComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-a.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-a.tsx
index 61e19b4d9f..a190b24202 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-a.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-a.tsx
@@ -1,6 +1,4 @@
-import { createFileRoute } from '@tanstack/react-router'
-
-export const Route = createFileRoute('/_layout/_layout-2/layout-a')({
+export const Route = createFileRoute({
component: LayoutAComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-b.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-b.tsx
index cceed1fb9a..505f8f6fbf 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-b.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/_layout/_layout-2/layout-b.tsx
@@ -1,6 +1,4 @@
-import { createFileRoute } from '@tanstack/react-router'
-
-export const Route = createFileRoute('/_layout/_layout-2/layout-b')({
+export const Route = createFileRoute({
component: LayoutBComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/index.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/index.tsx
index eac82a9174..b23956ae17 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/index.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/index.tsx
@@ -1,7 +1,6 @@
import * as React from 'react'
-import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/')({
+export const Route = createFileRoute({
component: Home,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.$postId.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.$postId.tsx
index 47d1148be2..805fa37ed3 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.$postId.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.$postId.tsx
@@ -1,9 +1,9 @@
import * as React from 'react'
-import { ErrorComponent, createFileRoute } from '@tanstack/react-router'
+import { ErrorComponent } from '@tanstack/react-router'
import { fetchPost } from '../posts'
import type { ErrorComponentProps } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/$postId')({
+export const Route = createFileRoute({
loader: async ({ params: { postId } }) => fetchPost(postId),
errorComponent: PostErrorComponent as any,
notFoundComponent: () => {
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.index.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.index.tsx
index 056433ca0a..fdbe5865e5 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.index.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.index.tsx
@@ -1,7 +1,6 @@
import * as React from 'react'
-import { createFileRoute } from '@tanstack/react-router'
-export const Route = createFileRoute('/posts/')({
+export const Route = createFileRoute({
component: PostsIndexComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.tsx
index c7a09ed7f8..4469b2216a 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/posts.tsx
@@ -1,8 +1,8 @@
import * as React from 'react'
-import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
+import { Link, Outlet } from '@tanstack/react-router'
import { fetchPosts } from '../posts'
-export const Route = createFileRoute('/posts')({
+export const Route = createFileRoute({
loader: fetchPosts,
component: PostsComponent,
})
diff --git a/e2e/react-router/basic-file-based-code-splitting/src/routes/viewport-test.tsx b/e2e/react-router/basic-file-based-code-splitting/src/routes/viewport-test.tsx
index d60bf062d3..b182feb7b1 100644
--- a/e2e/react-router/basic-file-based-code-splitting/src/routes/viewport-test.tsx
+++ b/e2e/react-router/basic-file-based-code-splitting/src/routes/viewport-test.tsx
@@ -1,5 +1,3 @@
-import { createFileRoute } from '@tanstack/react-router'
-
-export const Route = createFileRoute('/viewport-test')({
+export const Route = createFileRoute({
component: () =>