@tanstack/create 0.49.3 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +732 -0
- package/dist/add-ons.js +42 -2
- package/dist/add-to-app.js +36 -7
- package/dist/custom-add-ons/add-on.js +2 -26
- package/dist/custom-add-ons/starter.js +1 -2
- package/dist/file-helpers.js +11 -10
- package/dist/frameworks/react/add-ons/ai/info.json +1 -1
- package/dist/frameworks/react/add-ons/apollo-client/info.json +1 -1
- package/dist/frameworks/react/add-ons/better-auth/info.json +0 -2
- package/dist/frameworks/react/add-ons/clerk/info.json +0 -1
- package/dist/frameworks/react/add-ons/db/info.json +1 -1
- package/dist/frameworks/react/add-ons/drizzle/info.json +1 -1
- package/dist/frameworks/react/add-ons/drizzle/package.json.ejs +4 -0
- package/dist/frameworks/react/add-ons/mcp/info.json +1 -2
- package/dist/frameworks/react/add-ons/neon/assets/neon-vite-plugin.ts +1 -1
- package/dist/frameworks/react/add-ons/neon/info.json +1 -2
- package/dist/frameworks/react/add-ons/oRPC/info.json +1 -1
- package/dist/frameworks/react/add-ons/paraglide/info.json +1 -1
- package/dist/frameworks/react/add-ons/prisma/info.json +1 -1
- package/dist/frameworks/react/add-ons/prisma/package.json.ejs +4 -0
- package/dist/frameworks/react/add-ons/sentry/info.json +1 -2
- package/dist/frameworks/react/add-ons/tRPC/info.json +1 -1
- package/dist/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +1 -29
- package/dist/frameworks/react/add-ons/workos/info.json +0 -1
- package/dist/frameworks/react/hosts/cloudflare/info.json +0 -1
- package/dist/frameworks/react/hosts/netlify/info.json +0 -1
- package/dist/frameworks/react/hosts/nitro/info.json +0 -1
- package/dist/frameworks/react/hosts/railway/info.json +0 -1
- package/dist/frameworks/react/index.js +1 -6
- package/dist/frameworks/react/project/base/README.md.ejs +86 -436
- package/dist/frameworks/react/project/base/_dot_gitignore +4 -0
- package/dist/frameworks/react/project/base/package.json +8 -5
- package/dist/frameworks/react/project/base/src/components/Header.tsx.ejs +2 -32
- package/dist/frameworks/react/project/base/src/routes/__root.tsx.ejs +4 -44
- package/dist/frameworks/react/project/base/src/routes/index.tsx.ejs +99 -61
- package/dist/frameworks/react/project/base/src/styles.css.ejs +3 -3
- package/dist/frameworks/react/project/base/tsconfig.json.ejs +1 -1
- package/dist/frameworks/react/project/base/vite.config.ts.ejs +33 -27
- package/dist/frameworks/react/project/packages.json +2 -2
- package/dist/frameworks/solid/add-ons/better-auth/info.json +1 -1
- package/dist/frameworks/solid/hosts/cloudflare/info.json +0 -1
- package/dist/frameworks/solid/hosts/netlify/info.json +0 -1
- package/dist/frameworks/solid/hosts/nitro/info.json +0 -1
- package/dist/frameworks/solid/hosts/railway/info.json +0 -1
- package/dist/frameworks/solid/index.js +1 -6
- package/dist/frameworks/solid/project/base/README.md.ejs +43 -117
- package/dist/frameworks/solid/project/base/_dot_gitignore +4 -0
- package/dist/frameworks/solid/project/base/package.json +8 -3
- package/dist/frameworks/solid/project/base/src/components/Header.tsx.ejs +2 -25
- package/dist/frameworks/solid/project/base/src/routes/__root.tsx.ejs +3 -30
- package/dist/frameworks/solid/project/base/src/routes/index.tsx.ejs +97 -35
- package/dist/frameworks/solid/project/base/tsconfig.json.ejs +1 -1
- package/dist/frameworks/solid/project/base/vite.config.ts.ejs +15 -20
- package/dist/frameworks/solid/project/packages.json +2 -2
- package/dist/frameworks.js +0 -1
- package/dist/package-json.js +6 -10
- package/dist/template-file.js +21 -7
- package/dist/types/custom-add-ons/add-on.d.ts +1 -1
- package/dist/types/file-helpers.d.ts +0 -1
- package/dist/types/types.d.ts +12 -12
- package/dist/types.js +1 -2
- package/package.json +1 -1
- package/src/add-ons.ts +54 -2
- package/src/add-to-app.ts +42 -7
- package/src/custom-add-ons/add-on.ts +2 -33
- package/src/custom-add-ons/starter.ts +1 -2
- package/src/file-helpers.ts +11 -10
- package/src/frameworks/react/add-ons/ai/info.json +1 -1
- package/src/frameworks/react/add-ons/apollo-client/info.json +1 -1
- package/src/frameworks/react/add-ons/better-auth/info.json +0 -2
- package/src/frameworks/react/add-ons/clerk/info.json +0 -1
- package/src/frameworks/react/add-ons/db/info.json +1 -1
- package/src/frameworks/react/add-ons/drizzle/info.json +1 -1
- package/src/frameworks/react/add-ons/drizzle/package.json.ejs +4 -0
- package/src/frameworks/react/add-ons/mcp/info.json +1 -2
- package/src/frameworks/react/add-ons/neon/assets/neon-vite-plugin.ts +1 -1
- package/src/frameworks/react/add-ons/neon/info.json +1 -2
- package/src/frameworks/react/add-ons/oRPC/info.json +1 -1
- package/src/frameworks/react/add-ons/paraglide/info.json +1 -1
- package/src/frameworks/react/add-ons/prisma/info.json +1 -1
- package/src/frameworks/react/add-ons/prisma/package.json.ejs +4 -0
- package/src/frameworks/react/add-ons/sentry/info.json +1 -2
- package/src/frameworks/react/add-ons/tRPC/info.json +1 -1
- package/src/frameworks/react/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +1 -29
- package/src/frameworks/react/add-ons/workos/info.json +0 -1
- package/src/frameworks/react/hosts/cloudflare/info.json +0 -1
- package/src/frameworks/react/hosts/netlify/info.json +0 -1
- package/src/frameworks/react/hosts/nitro/info.json +0 -1
- package/src/frameworks/react/hosts/railway/info.json +0 -1
- package/src/frameworks/react/index.ts +1 -6
- package/src/frameworks/react/project/base/README.md.ejs +86 -436
- package/src/frameworks/react/project/base/_dot_gitignore +4 -0
- package/src/frameworks/react/project/base/package.json +8 -5
- package/src/frameworks/react/project/base/src/components/Header.tsx.ejs +2 -32
- package/src/frameworks/react/project/base/src/routes/__root.tsx.ejs +4 -44
- package/src/frameworks/react/project/base/src/routes/index.tsx.ejs +99 -61
- package/src/frameworks/react/project/base/src/styles.css.ejs +3 -3
- package/src/frameworks/react/project/base/tsconfig.json.ejs +1 -1
- package/src/frameworks/react/project/base/vite.config.ts.ejs +33 -27
- package/src/frameworks/react/project/packages.json +2 -2
- package/src/frameworks/solid/add-ons/better-auth/info.json +1 -1
- package/src/frameworks/solid/hosts/cloudflare/info.json +0 -1
- package/src/frameworks/solid/hosts/netlify/info.json +0 -1
- package/src/frameworks/solid/hosts/nitro/info.json +0 -1
- package/src/frameworks/solid/hosts/railway/info.json +0 -1
- package/src/frameworks/solid/index.ts +1 -6
- package/src/frameworks/solid/project/base/README.md.ejs +43 -117
- package/src/frameworks/solid/project/base/_dot_gitignore +4 -0
- package/src/frameworks/solid/project/base/package.json +8 -3
- package/src/frameworks/solid/project/base/src/components/Header.tsx.ejs +2 -25
- package/src/frameworks/solid/project/base/src/routes/__root.tsx.ejs +3 -30
- package/src/frameworks/solid/project/base/src/routes/index.tsx.ejs +97 -35
- package/src/frameworks/solid/project/base/tsconfig.json.ejs +1 -1
- package/src/frameworks/solid/project/base/vite.config.ts.ejs +15 -20
- package/src/frameworks/solid/project/packages.json +2 -2
- package/src/frameworks.ts +0 -1
- package/src/package-json.ts +6 -10
- package/src/template-file.ts +27 -8
- package/src/types.ts +1 -2
- package/tests/add-to-app.test.ts +37 -0
- package/tests/file-helper.test.ts +23 -2
- package/tests/package-json.test.ts +32 -0
- package/tests/template-file.test.ts +28 -0
- package/dist/frameworks/react/add-ons/module-federation/assets/module-federation.config.js.ejs +0 -31
- package/dist/frameworks/react/add-ons/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/dist/frameworks/react/add-ons/module-federation/assets/src/demo-mf-self-contained.tsx +0 -11
- package/dist/frameworks/react/add-ons/module-federation/info.json +0 -11
- package/dist/frameworks/react/add-ons/module-federation/package.json +0 -5
- package/dist/frameworks/react/add-ons/module-federation/small-logo.svg +0 -87
- package/dist/frameworks/react/add-ons/start/assets/_dot_gitignore.append +0 -3
- package/dist/frameworks/react/add-ons/start/assets/src/data/demo.punk-songs.ts +0 -13
- package/dist/frameworks/react/add-ons/start/assets/src/router.tsx.ejs +0 -77
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/api.names.ts +0 -10
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/api.tq-todos.ts.ejs +0 -35
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.api-request.tsx.ejs +0 -68
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.css.ejs +0 -43
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.server-funcs.tsx.ejs +0 -183
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.data-only.tsx.ejs +0 -55
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.full-ssr.tsx.ejs +0 -55
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.index.tsx.ejs +0 -62
- package/dist/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.spa-mode.tsx.ejs +0 -62
- package/dist/frameworks/react/add-ons/start/assets/src/routes/index.tsx.ejs +0 -142
- package/dist/frameworks/react/add-ons/start/assets/src/server.ts.ejs +0 -9
- package/dist/frameworks/react/add-ons/start/assets/vite.config.ts.ejs +0 -40
- package/dist/frameworks/react/add-ons/start/info.json +0 -61
- package/dist/frameworks/react/add-ons/start/package.json +0 -12
- package/dist/frameworks/react/add-ons/start/small-logo.svg +0 -1
- package/dist/frameworks/react/project/base/index.html.ejs +0 -20
- package/dist/frameworks/react/project/base/src/App.css.ejs +0 -38
- package/dist/frameworks/react/project/base/src/App.tsx.ejs +0 -63
- package/dist/frameworks/react/project/base/src/components/Header.css.ejs +0 -18
- package/dist/frameworks/react/project/base/src/logo.svg +0 -12
- package/dist/frameworks/react/project/base/src/main.tsx.ejs +0 -166
- package/dist/frameworks/react/project/base/src/reportWebVitals.ts.ejs +0 -28
- package/dist/frameworks/solid/add-ons/module-federation/assets/module-federation.config.js.ejs +0 -27
- package/dist/frameworks/solid/add-ons/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/dist/frameworks/solid/add-ons/module-federation/assets/src/demo-mf-self-contained.tsx +0 -9
- package/dist/frameworks/solid/add-ons/module-federation/info.json +0 -10
- package/dist/frameworks/solid/add-ons/module-federation/package.json +0 -5
- package/dist/frameworks/solid/add-ons/module-federation/small-logo.svg +0 -87
- package/dist/frameworks/solid/add-ons/start/assets/public/tanstack-circle-logo.png +0 -0
- package/dist/frameworks/solid/add-ons/start/assets/public/tanstack-word-logo-white.svg +0 -1
- package/dist/frameworks/solid/add-ons/start/assets/src/router.tsx.ejs +0 -30
- package/dist/frameworks/solid/add-ons/start/assets/src/routes/demo.start.server-funcs.tsx +0 -49
- package/dist/frameworks/solid/add-ons/start/assets/src/routes/index.tsx.ejs +0 -138
- package/dist/frameworks/solid/add-ons/start/assets/vite.config.ts.ejs +0 -22
- package/dist/frameworks/solid/add-ons/start/info.json +0 -18
- package/dist/frameworks/solid/add-ons/start/package.json +0 -15
- package/dist/frameworks/solid/add-ons/start/small-logo.svg +0 -1
- package/dist/frameworks/solid/project/base/index.html.ejs +0 -20
- package/dist/frameworks/solid/project/base/src/App.css.ejs +0 -38
- package/dist/frameworks/solid/project/base/src/App.tsx.ejs +0 -34
- package/dist/frameworks/solid/project/base/src/logo.svg +0 -120
- package/dist/frameworks/solid/project/base/src/main.tsx.ejs +0 -126
- package/src/frameworks/react/add-ons/module-federation/assets/module-federation.config.js.ejs +0 -31
- package/src/frameworks/react/add-ons/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/src/frameworks/react/add-ons/module-federation/assets/src/demo-mf-self-contained.tsx +0 -11
- package/src/frameworks/react/add-ons/module-federation/info.json +0 -11
- package/src/frameworks/react/add-ons/module-federation/package.json +0 -5
- package/src/frameworks/react/add-ons/module-federation/small-logo.svg +0 -87
- package/src/frameworks/react/add-ons/start/assets/_dot_gitignore.append +0 -3
- package/src/frameworks/react/add-ons/start/assets/src/data/demo.punk-songs.ts +0 -13
- package/src/frameworks/react/add-ons/start/assets/src/router.tsx.ejs +0 -77
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/api.names.ts +0 -10
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/api.tq-todos.ts.ejs +0 -35
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.api-request.tsx.ejs +0 -68
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.css.ejs +0 -43
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.server-funcs.tsx.ejs +0 -183
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.data-only.tsx.ejs +0 -55
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.full-ssr.tsx.ejs +0 -55
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.index.tsx.ejs +0 -62
- package/src/frameworks/react/add-ons/start/assets/src/routes/demo/start.ssr.spa-mode.tsx.ejs +0 -62
- package/src/frameworks/react/add-ons/start/assets/src/routes/index.tsx.ejs +0 -142
- package/src/frameworks/react/add-ons/start/assets/src/server.ts.ejs +0 -9
- package/src/frameworks/react/add-ons/start/assets/vite.config.ts.ejs +0 -40
- package/src/frameworks/react/add-ons/start/info.json +0 -61
- package/src/frameworks/react/add-ons/start/package.json +0 -12
- package/src/frameworks/react/add-ons/start/small-logo.svg +0 -1
- package/src/frameworks/react/project/base/index.html.ejs +0 -20
- package/src/frameworks/react/project/base/src/App.css.ejs +0 -38
- package/src/frameworks/react/project/base/src/App.tsx.ejs +0 -63
- package/src/frameworks/react/project/base/src/components/Header.css.ejs +0 -18
- package/src/frameworks/react/project/base/src/logo.svg +0 -12
- package/src/frameworks/react/project/base/src/main.tsx.ejs +0 -166
- package/src/frameworks/react/project/base/src/reportWebVitals.ts.ejs +0 -28
- package/src/frameworks/solid/add-ons/module-federation/assets/module-federation.config.js.ejs +0 -27
- package/src/frameworks/solid/add-ons/module-federation/assets/src/demo-mf-component.tsx +0 -3
- package/src/frameworks/solid/add-ons/module-federation/assets/src/demo-mf-self-contained.tsx +0 -9
- package/src/frameworks/solid/add-ons/module-federation/info.json +0 -10
- package/src/frameworks/solid/add-ons/module-federation/package.json +0 -5
- package/src/frameworks/solid/add-ons/module-federation/small-logo.svg +0 -87
- package/src/frameworks/solid/add-ons/start/assets/public/tanstack-circle-logo.png +0 -0
- package/src/frameworks/solid/add-ons/start/assets/public/tanstack-word-logo-white.svg +0 -1
- package/src/frameworks/solid/add-ons/start/assets/src/router.tsx.ejs +0 -30
- package/src/frameworks/solid/add-ons/start/assets/src/routes/demo.start.server-funcs.tsx +0 -49
- package/src/frameworks/solid/add-ons/start/assets/src/routes/index.tsx.ejs +0 -138
- package/src/frameworks/solid/add-ons/start/assets/vite.config.ts.ejs +0 -22
- package/src/frameworks/solid/add-ons/start/info.json +0 -18
- package/src/frameworks/solid/add-ons/start/package.json +0 -15
- package/src/frameworks/solid/add-ons/start/small-logo.svg +0 -1
- package/src/frameworks/solid/project/base/index.html.ejs +0 -20
- package/src/frameworks/solid/project/base/src/App.css.ejs +0 -38
- package/src/frameworks/solid/project/base/src/App.tsx.ejs +0 -34
- package/src/frameworks/solid/project/base/src/logo.svg +0 -120
- package/src/frameworks/solid/project/base/src/main.tsx.ejs +0 -126
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Welcome to your new TanStack app!
|
|
1
|
+
Welcome to your new TanStack Start app!
|
|
2
2
|
|
|
3
3
|
# Getting Started
|
|
4
4
|
|
|
@@ -26,11 +26,17 @@ This project uses [Vitest](https://vitest.dev/) for testing. You can run the tes
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## Styling
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
|
|
32
|
+
### Removing Tailwind CSS
|
|
33
|
+
|
|
34
|
+
If you prefer not to use Tailwind CSS:
|
|
35
|
+
|
|
36
|
+
1. Remove the demo pages in `src/routes/demo/`
|
|
37
|
+
2. Replace the Tailwind import in `src/styles.css` with your own styles
|
|
38
|
+
3. Remove `tailwindcss()` from the plugins array in `vite.config.ts`
|
|
39
|
+
4. Uninstall the packages: `<%= getPackageManagerAddScript('@tailwindcss/vite tailwindcss', true) %>`
|
|
34
40
|
<% if (addOnEnabled.biome || addOnEnabled.eslint) { %>
|
|
35
41
|
## Linting & Formatting
|
|
36
42
|
<% if (addOnEnabled.biome) { %>
|
|
@@ -50,48 +56,15 @@ This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.
|
|
|
50
56
|
<% } %>
|
|
51
57
|
|
|
52
58
|
## Routing
|
|
53
|
-
<% if (fileRouter) { %>This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.<% } else { %>This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a code based router. Which means that the routes are defined in code (in the `./src/main.<%= jsx %>` file). If you like you can also use a file based routing setup by following the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) guide.<% } %>
|
|
54
|
-
|
|
55
|
-
### Adding A Route
|
|
56
|
-
<% if (fileRouter) { %>
|
|
57
|
-
To add a new route to your application just add another a new file in the `./src/routes` directory.
|
|
58
|
-
|
|
59
|
-
TanStack will automatically generate the content of the route file for you.
|
|
60
|
-
<% } else { %>
|
|
61
|
-
To add a new route to your application just add another `createRoute` call to the `./src/main.<%= jsx %>` file. The example below adds a new `/about`route to the root route.
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
const aboutRoute = createRoute({
|
|
65
|
-
getParentRoute: () => rootRoute,
|
|
66
|
-
path: "/about",
|
|
67
|
-
component: () => <h1>About</h1>,
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
You will also need to add the route to the `routeTree` in the `./src/main.<%= jsx %>` file.
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute]);
|
|
75
|
-
```
|
|
76
59
|
|
|
77
|
-
|
|
60
|
+
This project uses [TanStack Router](https://tanstack.com/router) with file-based routing. Routes are managed as files in `src/routes`.
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
import About from "./components/About.<%= jsx %>";
|
|
62
|
+
### Adding A Route
|
|
83
63
|
|
|
84
|
-
|
|
85
|
-
getParentRoute: () => rootRoute,
|
|
86
|
-
path: "/about",
|
|
87
|
-
component: About,
|
|
88
|
-
});
|
|
89
|
-
```
|
|
64
|
+
To add a new route to your application just add a new file in the `./src/routes` directory.
|
|
90
65
|
|
|
91
|
-
|
|
66
|
+
TanStack will automatically generate the content of the route file for you.
|
|
92
67
|
|
|
93
|
-
For more information on the options you have when you are creating code based routes check out the [Code Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing) documentation.
|
|
94
|
-
<% } %>
|
|
95
68
|
Now that you have two routes you can use a `Link` component to navigate between them.
|
|
96
69
|
|
|
97
70
|
### Adding Links
|
|
@@ -114,250 +87,85 @@ More information on the `Link` component can be found in the [Link documentation
|
|
|
114
87
|
|
|
115
88
|
### Using A Layout
|
|
116
89
|
|
|
117
|
-
|
|
118
|
-
Layouts can be used to wrap the contents of the routes in menus, headers, footers, etc.
|
|
119
|
-
|
|
120
|
-
There is already a layout in the `src/main.<%= jsx %>` file:
|
|
121
|
-
|
|
122
|
-
```tsx
|
|
123
|
-
const rootRoute = createRootRoute({
|
|
124
|
-
component: () => (
|
|
125
|
-
<>
|
|
126
|
-
<Outlet />
|
|
127
|
-
<TanStackRouterDevtools />
|
|
128
|
-
</>
|
|
129
|
-
),
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
You can use the React component specified in the `component` property of the `rootRoute` to wrap the contents of the routes. The `<Outlet />` component is used to render the current route within the body of the layout. For example you could add a header to the layout like so:
|
|
134
|
-
|
|
135
|
-
```tsx
|
|
136
|
-
import { Link } from "@tanstack/react-router";
|
|
137
|
-
|
|
138
|
-
const rootRoute = createRootRoute({
|
|
139
|
-
component: () => (
|
|
140
|
-
<>
|
|
141
|
-
<header>
|
|
142
|
-
<nav>
|
|
143
|
-
<Link to="/">Home</Link>
|
|
144
|
-
<Link to="/about">About</Link>
|
|
145
|
-
</nav>
|
|
146
|
-
</header>
|
|
147
|
-
<Outlet />
|
|
148
|
-
<TanStackRouterDevtools />
|
|
149
|
-
</>
|
|
150
|
-
),
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
<% } else { %>In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.
|
|
90
|
+
In the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you render `{children}` in the `shellComponent`.
|
|
154
91
|
|
|
155
92
|
Here is an example layout that includes a header:
|
|
156
93
|
|
|
157
94
|
```tsx
|
|
158
|
-
import {
|
|
159
|
-
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
|
|
160
|
-
|
|
161
|
-
import { Link } from "@tanstack/react-router";
|
|
95
|
+
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
|
|
162
96
|
|
|
163
97
|
export const Route = createRootRoute({
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
<
|
|
174
|
-
|
|
98
|
+
head: () => ({
|
|
99
|
+
meta: [
|
|
100
|
+
{ charSet: 'utf-8' },
|
|
101
|
+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
102
|
+
{ title: 'My App' },
|
|
103
|
+
],
|
|
104
|
+
}),
|
|
105
|
+
shellComponent: ({ children }) => (
|
|
106
|
+
<html lang="en">
|
|
107
|
+
<head>
|
|
108
|
+
<HeadContent />
|
|
109
|
+
</head>
|
|
110
|
+
<body>
|
|
111
|
+
<header>
|
|
112
|
+
<nav>
|
|
113
|
+
<Link to="/">Home</Link>
|
|
114
|
+
<Link to="/about">About</Link>
|
|
115
|
+
</nav>
|
|
116
|
+
</header>
|
|
117
|
+
{children}
|
|
118
|
+
<Scripts />
|
|
119
|
+
</body>
|
|
120
|
+
</html>
|
|
175
121
|
),
|
|
176
122
|
})
|
|
177
123
|
```
|
|
178
|
-
<% } %>
|
|
179
|
-
The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
|
|
180
124
|
|
|
181
125
|
More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
|
|
182
126
|
|
|
183
|
-
|
|
184
|
-
### Migrating To File Base Routing
|
|
185
|
-
|
|
186
|
-
First you need to add the Vite plugin for Tanstack Router:
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
<%= getPackageManagerAddScript("@tanstack/router-plugin", true) %>
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
From there you need to update your `vite.config.js` file to use the plugin:
|
|
193
|
-
|
|
194
|
-
```ts
|
|
195
|
-
import { defineConfig } from "vite";
|
|
196
|
-
import viteReact from "@vitejs/plugin-react";
|
|
197
|
-
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";<% if (tailwind) { %>
|
|
198
|
-
import tailwindcss from "@tailwindcss/vite";
|
|
199
|
-
<% } %>
|
|
200
|
-
|
|
201
|
-
// https://vitejs.dev/config/
|
|
202
|
-
export default defineConfig({
|
|
203
|
-
plugins: [
|
|
204
|
-
TanStackRouterVite(),
|
|
205
|
-
viteReact()<% if (tailwind) { %>,
|
|
206
|
-
tailwindcss()<% } %>
|
|
207
|
-
],
|
|
208
|
-
});
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
Now you'll need to rearrange your files a little bit. That starts with creating a `routes` directory in the `src` directory:
|
|
212
|
-
|
|
213
|
-
```bash
|
|
214
|
-
mkdir src/routes
|
|
215
|
-
```
|
|
127
|
+
## Server Functions
|
|
216
128
|
|
|
217
|
-
|
|
129
|
+
TanStack Start provides server functions that allow you to write server-side code that seamlessly integrates with your client components.
|
|
218
130
|
|
|
219
131
|
```tsx
|
|
220
|
-
import {
|
|
221
|
-
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
|
222
|
-
|
|
223
|
-
export const Route = createRootRoute({
|
|
224
|
-
component: () => (
|
|
225
|
-
<>
|
|
226
|
-
<Outlet />
|
|
227
|
-
<TanStackRouterDevtools />
|
|
228
|
-
</>
|
|
229
|
-
),
|
|
230
|
-
});
|
|
231
|
-
```
|
|
132
|
+
import { createServerFn } from '@tanstack/react-start'
|
|
232
133
|
|
|
233
|
-
|
|
134
|
+
const getServerTime = createServerFn({
|
|
135
|
+
method: 'GET',
|
|
136
|
+
}).handler(async () => {
|
|
137
|
+
return new Date().toISOString()
|
|
138
|
+
})
|
|
234
139
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function App() {
|
|
246
|
-
return (<% if (tailwind) { %>
|
|
247
|
-
<div className="text-center">
|
|
248
|
-
<header className="min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)]">
|
|
249
|
-
<img
|
|
250
|
-
src={logo}
|
|
251
|
-
className="h-[40vmin] pointer-events-none animate-[spin_20s_linear_infinite]"
|
|
252
|
-
alt="logo"
|
|
253
|
-
/>
|
|
254
|
-
<p>
|
|
255
|
-
Edit <code>src/App.tsx</code> and save to reload.
|
|
256
|
-
</p>
|
|
257
|
-
<a
|
|
258
|
-
className="text-[#61dafb] hover:underline"
|
|
259
|
-
href="https://reactjs.org"
|
|
260
|
-
target="_blank"
|
|
261
|
-
rel="noopener noreferrer"
|
|
262
|
-
>
|
|
263
|
-
Learn React
|
|
264
|
-
</a>
|
|
265
|
-
<a
|
|
266
|
-
className="text-[#61dafb] hover:underline"
|
|
267
|
-
href="https://tanstack.com"
|
|
268
|
-
target="_blank"
|
|
269
|
-
rel="noopener noreferrer"
|
|
270
|
-
>
|
|
271
|
-
Learn TanStack
|
|
272
|
-
</a>
|
|
273
|
-
</header>
|
|
274
|
-
</div>
|
|
275
|
-
<% } else { %>
|
|
276
|
-
<div className="App">
|
|
277
|
-
<header className="App-header">
|
|
278
|
-
<img src={logo} className="App-logo" alt="logo" />
|
|
279
|
-
<p>
|
|
280
|
-
Edit <code>src/App.tsx</code> and save to reload.
|
|
281
|
-
</p>
|
|
282
|
-
<a
|
|
283
|
-
className="App-link"
|
|
284
|
-
href="https://reactjs.org"
|
|
285
|
-
target="_blank"
|
|
286
|
-
rel="noopener noreferrer"
|
|
287
|
-
>
|
|
288
|
-
Learn React
|
|
289
|
-
</a>
|
|
290
|
-
<a
|
|
291
|
-
className="App-link"
|
|
292
|
-
href="https://tanstack.com"
|
|
293
|
-
target="_blank"
|
|
294
|
-
rel="noopener noreferrer"
|
|
295
|
-
>
|
|
296
|
-
Learn TanStack
|
|
297
|
-
</a>
|
|
298
|
-
</header>
|
|
299
|
-
</div>
|
|
300
|
-
<% } %> );
|
|
140
|
+
// Use in a component
|
|
141
|
+
function MyComponent() {
|
|
142
|
+
const [time, setTime] = useState('')
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
getServerTime().then(setTime)
|
|
146
|
+
}, [])
|
|
147
|
+
|
|
148
|
+
return <div>Server time: {time}</div>
|
|
301
149
|
}
|
|
302
150
|
```
|
|
303
151
|
|
|
304
|
-
|
|
152
|
+
## API Routes
|
|
305
153
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
Finally the `src/main.<%= jsx %>` file can be simplified down to this:
|
|
154
|
+
You can create API routes by using the `server` property in your route definitions:
|
|
309
155
|
|
|
310
156
|
```tsx
|
|
311
|
-
import {
|
|
312
|
-
import
|
|
313
|
-
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
|
314
|
-
|
|
315
|
-
// Import the generated route tree
|
|
316
|
-
import { routeTree } from "./routeTree.gen";
|
|
317
|
-
|
|
318
|
-
import "./styles.css";
|
|
319
|
-
import reportWebVitals from "./reportWebVitals.<%= js %>";
|
|
320
|
-
|
|
321
|
-
// Create a new router instance
|
|
322
|
-
const router = createRouter({
|
|
323
|
-
routeTree,
|
|
324
|
-
defaultPreload: "intent",
|
|
325
|
-
defaultPreloadStaleTime: 0,
|
|
326
|
-
scrollRestoration: true,
|
|
327
|
-
defaultStructuralSharing: true
|
|
328
|
-
});
|
|
329
|
-
<% if (typescript) { %>
|
|
330
|
-
// Register the router instance for type safety
|
|
331
|
-
declare module "@tanstack/react-router" {
|
|
332
|
-
interface Register {
|
|
333
|
-
router: typeof router;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
157
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
158
|
+
import { json } from '@tanstack/react-start'
|
|
336
159
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
root.render(
|
|
345
|
-
<StrictMode>
|
|
346
|
-
<RouterProvider router={router} />
|
|
347
|
-
</StrictMode>
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// If you want to start measuring performance in your app, pass a function
|
|
352
|
-
// to log results (for example: reportWebVitals(console.log))
|
|
353
|
-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
354
|
-
reportWebVitals();
|
|
160
|
+
export const Route = createFileRoute('/api/hello')({
|
|
161
|
+
server: {
|
|
162
|
+
handlers: {
|
|
163
|
+
GET: () => json({ message: 'Hello, World!' }),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
})
|
|
355
167
|
```
|
|
356
168
|
|
|
357
|
-
Now you've got a file based routing setup in your project! Let's have some fun with it! Just create a file in `about.<%= jsx %>` in `src/routes` and it if the application is running TanStack will automatically add contents to the file and you'll have the start of your `/about` route ready to go with no additional work. You can see why folks find File Based Routing so easy to use.
|
|
358
|
-
|
|
359
|
-
You can find out everything you need to know on how to use file based routing in the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) documentation.
|
|
360
|
-
<% } %>
|
|
361
169
|
## Data Fetching
|
|
362
170
|
|
|
363
171
|
There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
|
|
@@ -365,189 +173,29 @@ There are multiple ways to fetch data in your application. You can use TanStack
|
|
|
365
173
|
For example:
|
|
366
174
|
|
|
367
175
|
```tsx
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
176
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
177
|
+
|
|
178
|
+
export const Route = createFileRoute('/people')({
|
|
371
179
|
loader: async () => {
|
|
372
|
-
const response = await fetch(
|
|
373
|
-
return response.json()
|
|
374
|
-
results: {
|
|
375
|
-
name: string;
|
|
376
|
-
}[];
|
|
377
|
-
}>;
|
|
378
|
-
<% } else { %>
|
|
379
|
-
return response.json();
|
|
380
|
-
<% } %> },
|
|
381
|
-
component: () => {
|
|
382
|
-
const data = peopleRoute.useLoaderData();
|
|
383
|
-
return (
|
|
384
|
-
<ul>
|
|
385
|
-
{data.results.map((person) => (
|
|
386
|
-
<li key={person.name}>{person.name}</li>
|
|
387
|
-
))}
|
|
388
|
-
</ul>
|
|
389
|
-
);
|
|
180
|
+
const response = await fetch('https://swapi.dev/api/people')
|
|
181
|
+
return response.json()
|
|
390
182
|
},
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
|
|
395
|
-
|
|
396
|
-
### React-Query
|
|
397
|
-
|
|
398
|
-
React-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.
|
|
399
|
-
|
|
400
|
-
First add your dependencies:
|
|
401
|
-
|
|
402
|
-
```bash
|
|
403
|
-
<%= getPackageManagerAddScript("@tanstack/react-query @tanstack/react-query-devtools") %>
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
Next we'll need to create a query client and provider. We recommend putting those in `main.<%= jsx %>`.
|
|
407
|
-
|
|
408
|
-
```tsx
|
|
409
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
410
|
-
|
|
411
|
-
// ...
|
|
412
|
-
|
|
413
|
-
const queryClient = new QueryClient();
|
|
414
|
-
|
|
415
|
-
// ...
|
|
416
|
-
|
|
417
|
-
if (!rootElement.innerHTML) {
|
|
418
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
419
|
-
|
|
420
|
-
root.render(
|
|
421
|
-
<QueryClientProvider client={queryClient}>
|
|
422
|
-
<RouterProvider router={router} />
|
|
423
|
-
</QueryClientProvider>
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
You can also add TanStack Query Devtools to the root route (optional).
|
|
429
|
-
|
|
430
|
-
```tsx
|
|
431
|
-
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
432
|
-
|
|
433
|
-
const rootRoute = createRootRoute({
|
|
434
|
-
component: () => (
|
|
435
|
-
<>
|
|
436
|
-
<Outlet />
|
|
437
|
-
<ReactQueryDevtools buttonPosition="top-right" />
|
|
438
|
-
<TanStackRouterDevtools />
|
|
439
|
-
</>
|
|
440
|
-
),
|
|
441
|
-
});
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
Now you can use `useQuery` to fetch your data.
|
|
445
|
-
|
|
446
|
-
```tsx
|
|
447
|
-
import { useQuery } from "@tanstack/react-query";
|
|
448
|
-
|
|
449
|
-
import "./App.css";
|
|
450
|
-
|
|
451
|
-
function App() {
|
|
452
|
-
const { data } = useQuery({
|
|
453
|
-
queryKey: ["people"],
|
|
454
|
-
queryFn: () =>
|
|
455
|
-
fetch("https://swapi.dev/api/people")
|
|
456
|
-
.then((res) => res.json())<% if (typescript) { %>
|
|
457
|
-
.then((data) => data.results as { name: string }[]),
|
|
458
|
-
<% } else { %>
|
|
459
|
-
.then((data) => data.results),
|
|
460
|
-
<% } %> initialData: [],
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
return (
|
|
464
|
-
<div>
|
|
465
|
-
<ul>
|
|
466
|
-
{data.map((person) => (
|
|
467
|
-
<li key={person.name}>{person.name}</li>
|
|
468
|
-
))}
|
|
469
|
-
</ul>
|
|
470
|
-
</div>
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
export default App;
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
478
|
-
|
|
479
|
-
## State Management
|
|
480
|
-
|
|
481
|
-
Another common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.
|
|
482
|
-
|
|
483
|
-
First you need to add TanStack Store as a dependency:
|
|
484
|
-
|
|
485
|
-
```bash
|
|
486
|
-
<%= getPackageManagerAddScript("@tanstack/store") %>
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
Now let's create a simple counter in the `src/App.<%= jsx %>` file as a demonstration.
|
|
490
|
-
|
|
491
|
-
```tsx
|
|
492
|
-
import { useStore } from "@tanstack/react-store";
|
|
493
|
-
import { Store } from "@tanstack/store";
|
|
494
|
-
import "./App.css";
|
|
495
|
-
|
|
496
|
-
const countStore = new Store(0);
|
|
497
|
-
|
|
498
|
-
function App() {
|
|
499
|
-
const count = useStore(countStore);
|
|
500
|
-
return (
|
|
501
|
-
<div>
|
|
502
|
-
<button onClick={() => countStore.setState((n) => n + 1)}>
|
|
503
|
-
Increment - {count}
|
|
504
|
-
</button>
|
|
505
|
-
</div>
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
export default App;
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
|
|
513
|
-
|
|
514
|
-
Let's check this out by doubling the count using derived state.
|
|
515
|
-
|
|
516
|
-
```tsx
|
|
517
|
-
import { useStore } from "@tanstack/react-store";
|
|
518
|
-
import { Store, Derived } from "@tanstack/store";
|
|
519
|
-
import "./App.css";
|
|
520
|
-
|
|
521
|
-
const countStore = new Store(0);
|
|
522
|
-
|
|
523
|
-
const doubledStore = new Derived({
|
|
524
|
-
fn: () => countStore.state * 2,
|
|
525
|
-
deps: [countStore],
|
|
526
|
-
});
|
|
527
|
-
doubledStore.mount();
|
|
528
|
-
|
|
529
|
-
function App() {
|
|
530
|
-
const count = useStore(countStore);
|
|
531
|
-
const doubledCount = useStore(doubledStore);
|
|
183
|
+
component: PeopleComponent,
|
|
184
|
+
})
|
|
532
185
|
|
|
186
|
+
function PeopleComponent() {
|
|
187
|
+
const data = Route.useLoaderData()
|
|
533
188
|
return (
|
|
534
|
-
<
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
);
|
|
189
|
+
<ul>
|
|
190
|
+
{data.results.map((person) => (
|
|
191
|
+
<li key={person.name}>{person.name}</li>
|
|
192
|
+
))}
|
|
193
|
+
</ul>
|
|
194
|
+
)
|
|
541
195
|
}
|
|
542
|
-
|
|
543
|
-
export default App;
|
|
544
196
|
```
|
|
545
197
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
Once we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.
|
|
549
|
-
|
|
550
|
-
You can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).
|
|
198
|
+
Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
|
|
551
199
|
|
|
552
200
|
# Demo files
|
|
553
201
|
|
|
@@ -556,3 +204,5 @@ Files prefixed with `demo` can be safely deleted. They are there to provide a st
|
|
|
556
204
|
# Learn More
|
|
557
205
|
|
|
558
206
|
You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
|
|
207
|
+
|
|
208
|
+
For TanStack Start specific documentation, visit [TanStack Start](https://tanstack.com/start).
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"private": true,
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "vite --port 3000",
|
|
7
|
-
"build": "vite build
|
|
6
|
+
"dev": "vite dev --port 3000",
|
|
7
|
+
"build": "vite build",
|
|
8
8
|
"preview": "vite preview",
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
"@tanstack/react-devtools": "^0.7.0",
|
|
13
13
|
"@tanstack/react-router": "^1.132.0",
|
|
14
14
|
"@tanstack/react-router-devtools": "^1.132.0",
|
|
15
|
+
"@tanstack/react-router-ssr-query": "^1.131.7",
|
|
16
|
+
"@tanstack/react-start": "^1.132.0",
|
|
17
|
+
"lucide-react": "^0.561.0",
|
|
15
18
|
"react": "^19.2.0",
|
|
16
|
-
"react-dom": "^19.2.0"
|
|
19
|
+
"react-dom": "^19.2.0",
|
|
20
|
+
"vite-tsconfig-paths": "^6.0.2"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@tanstack/devtools-vite": "^0.3.11",
|
|
@@ -25,7 +29,6 @@
|
|
|
25
29
|
"jsdom": "^27.0.0",
|
|
26
30
|
"typescript": "^5.7.2",
|
|
27
31
|
"vite": "^7.1.7",
|
|
28
|
-
"vitest": "^3.0.5"
|
|
29
|
-
"web-vitals": "^5.1.0"
|
|
32
|
+
"vitest": "^3.0.5"
|
|
30
33
|
}
|
|
31
34
|
}
|