@tanstack/react-router 1.159.14 → 1.160.2
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/dist/cjs/Asset.cjs +33 -19
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/index.dev.cjs +4 -0
- package/dist/cjs/index.dev.cjs.map +1 -1
- package/dist/cjs/link.cjs +6 -6
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/esm/Asset.js +33 -19
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.dev.js +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/link.js +6 -6
- package/dist/esm/link.js.map +1 -1
- package/dist/llms/rules/api.d.ts +1 -1
- package/dist/llms/rules/api.js +35 -0
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +2821 -253
- package/dist/llms/rules/installation.d.ts +1 -1
- package/dist/llms/rules/installation.js +376 -357
- package/dist/llms/rules/routing.d.ts +1 -1
- package/dist/llms/rules/routing.js +436 -31
- package/dist/llms/rules/setup-and-architecture.d.ts +1 -1
- package/dist/llms/rules/setup-and-architecture.js +253 -90
- package/package.json +2 -2
- package/src/Asset.tsx +45 -17
- package/src/index.tsx +6 -1
- package/src/link.tsx +7 -7
|
@@ -6,21 +6,23 @@ To set up TanStack Router manually in a React project, follow the steps below. T
|
|
|
6
6
|
|
|
7
7
|
#### Install TanStack Router, Vite Plugin, and the Router Devtools
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
Install the necessary core dependencies:
|
|
10
|
+
|
|
11
|
+
<!-- ::start:tabs variant="package-managers" -->
|
|
12
|
+
|
|
13
|
+
react: @tanstack/react-router @tanstack/react-router-devtools
|
|
14
|
+
solid: @tanstack/solid-router @tanstack/solid-router-devtools
|
|
15
|
+
|
|
16
|
+
<!-- ::end:tabs -->
|
|
17
|
+
|
|
18
|
+
Install the necessary development dependencies:
|
|
19
|
+
|
|
20
|
+
<!-- ::start:tabs variant="package-managers" mode="dev-install" -->
|
|
21
|
+
|
|
22
|
+
react: @tanstack/router-plugin
|
|
23
|
+
solid: @tanstack/router-plugin
|
|
24
|
+
|
|
25
|
+
<!-- ::end:tabs -->
|
|
24
26
|
|
|
25
27
|
#### Configure the Vite Plugin
|
|
26
28
|
|
|
@@ -54,9 +56,13 @@ Create the following files:
|
|
|
54
56
|
- \`src/routes/about.tsx\`
|
|
55
57
|
- \`src/main.tsx\`
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
<!-- ::start:framework -->
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
# React
|
|
62
|
+
|
|
63
|
+
<!-- ::start:tabs variant="files" -->
|
|
64
|
+
|
|
65
|
+
\`\`\`tsx title="src/routes/__root.tsx"
|
|
60
66
|
import { createRootRoute, Link, Outlet } from '@tanstack/react-router'
|
|
61
67
|
import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
|
|
62
68
|
|
|
@@ -79,9 +85,7 @@ const RootLayout = () => (
|
|
|
79
85
|
export const Route = createRootRoute({ component: RootLayout })
|
|
80
86
|
\`\`\`
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
\`\`\`tsx
|
|
88
|
+
\`\`\`tsx title="src/routes/index.tsx"
|
|
85
89
|
import { createFileRoute } from '@tanstack/react-router'
|
|
86
90
|
|
|
87
91
|
export const Route = createFileRoute('/')({
|
|
@@ -97,9 +101,7 @@ function Index() {
|
|
|
97
101
|
}
|
|
98
102
|
\`\`\`
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
\`\`\`tsx
|
|
104
|
+
\`\`\`tsx title="src/routes/about.tsx"
|
|
103
105
|
import { createFileRoute } from '@tanstack/react-router'
|
|
104
106
|
|
|
105
107
|
export const Route = createFileRoute('/about')({
|
|
@@ -111,13 +113,7 @@ function About() {
|
|
|
111
113
|
}
|
|
112
114
|
\`\`\`
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Regardless of whether you are using the \`@tanstack/router-plugin\` package and running the \`npm run dev\`/\`npm run build\` scripts, or manually running the \`tsr watch\`/\`tsr generate\` commands from your package scripts, the route tree file will be generated at \`src/routeTree.gen.ts\`.
|
|
117
|
-
|
|
118
|
-
Import the generated route tree and create a new router instance:
|
|
119
|
-
|
|
120
|
-
\`\`\`tsx
|
|
116
|
+
\`\`\`tsx title="src/main.tsx"
|
|
121
117
|
import { StrictMode } from 'react'
|
|
122
118
|
import ReactDOM from 'react-dom/client'
|
|
123
119
|
import { RouterProvider, createRouter } from '@tanstack/react-router'
|
|
@@ -147,6 +143,93 @@ if (!rootElement.innerHTML) {
|
|
|
147
143
|
}
|
|
148
144
|
\`\`\`
|
|
149
145
|
|
|
146
|
+
<!-- ::end:tabs -->
|
|
147
|
+
|
|
148
|
+
# Solid
|
|
149
|
+
|
|
150
|
+
<!-- ::start:tabs variant="files" -->
|
|
151
|
+
|
|
152
|
+
\`\`\`tsx title="src/routes/__root.tsx"
|
|
153
|
+
import { createRootRoute, Link, Outlet } from '@tanstack/solid-router'
|
|
154
|
+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
|
|
155
|
+
|
|
156
|
+
const RootLayout = () => (
|
|
157
|
+
<>
|
|
158
|
+
<div class="p-2 flex gap-2">
|
|
159
|
+
<Link to="/" class="[&.active]:font-bold">
|
|
160
|
+
Home
|
|
161
|
+
</Link>{' '}
|
|
162
|
+
<Link to="/about" class="[&.active]:font-bold">
|
|
163
|
+
About
|
|
164
|
+
</Link>
|
|
165
|
+
</div>
|
|
166
|
+
<hr />
|
|
167
|
+
<Outlet />
|
|
168
|
+
<TanStackRouterDevtools />
|
|
169
|
+
</>
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
export const Route = createRootRoute({ component: RootLayout })
|
|
173
|
+
\`\`\`
|
|
174
|
+
|
|
175
|
+
\`\`\`tsx title="src/routes/index.tsx"
|
|
176
|
+
import { createFileRoute } from '@tanstack/solid-router'
|
|
177
|
+
|
|
178
|
+
export const Route = createFileRoute('/')({
|
|
179
|
+
component: Index,
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
function Index() {
|
|
183
|
+
return (
|
|
184
|
+
<div class="p-2">
|
|
185
|
+
<h3>Welcome Home!</h3>
|
|
186
|
+
</div>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
\`\`\`
|
|
190
|
+
|
|
191
|
+
\`\`\`tsx title="src/routes/about.tsx"
|
|
192
|
+
import { createFileRoute } from '@tanstack/solid-router'
|
|
193
|
+
|
|
194
|
+
export const Route = createFileRoute('/about')({
|
|
195
|
+
component: About,
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
function About() {
|
|
199
|
+
return <div class="p-2">Hello from About!</div>
|
|
200
|
+
}
|
|
201
|
+
\`\`\`
|
|
202
|
+
|
|
203
|
+
\`\`\`tsx title="src/main.tsx"
|
|
204
|
+
/* @refresh reload */
|
|
205
|
+
import { render } from 'solid-js/web'
|
|
206
|
+
import { RouterProvider, createRouter } from '@tanstack/solid-router'
|
|
207
|
+
|
|
208
|
+
// Import the generated route tree
|
|
209
|
+
import { routeTree } from './routeTree.gen'
|
|
210
|
+
|
|
211
|
+
// Create a new router instance
|
|
212
|
+
const router = createRouter({ routeTree })
|
|
213
|
+
|
|
214
|
+
// Register the router instance for type safety
|
|
215
|
+
declare module '@tanstack/solid-router' {
|
|
216
|
+
interface Register {
|
|
217
|
+
router: typeof router
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Render the app
|
|
222
|
+
const rootElement = document.getElementById('root')!
|
|
223
|
+
|
|
224
|
+
render(() => <RouterProvider router={router} />, rootElement)
|
|
225
|
+
\`\`\`
|
|
226
|
+
|
|
227
|
+
<!-- ::end:tabs -->
|
|
228
|
+
|
|
229
|
+
<!-- ::end:framework -->
|
|
230
|
+
|
|
231
|
+
Regardless of whether you are using the \`@tanstack/router-plugin\` package and running the \`npm run dev\`/\`npm run build\` scripts, or manually running the \`tsr watch\`/\`tsr generate\` commands from your package scripts, the route tree file will be generated at \`src/routeTree.gen.ts\`.
|
|
232
|
+
|
|
150
233
|
If you are working with this pattern you should change the \`id\` of the root \`<div>\` on your \`index.html\` file to \`<div id='root'></div>\`
|
|
151
234
|
|
|
152
235
|
## Using Code-Based Route Configuration
|
|
@@ -154,6 +237,10 @@ If you are working with this pattern you should change the \`id\` of the root \`
|
|
|
154
237
|
> [!IMPORTANT]
|
|
155
238
|
> The following example shows how to configure routes using code, and for simplicity's sake is in a single file for this demo. While code-based generation allows you to declare many routes and even the router instance in a single file, we recommend splitting your routes into separate files for better organization and performance as your application grows.
|
|
156
239
|
|
|
240
|
+
<!-- ::start:framework -->
|
|
241
|
+
|
|
242
|
+
# React
|
|
243
|
+
|
|
157
244
|
\`\`\`tsx
|
|
158
245
|
import { StrictMode } from 'react'
|
|
159
246
|
import ReactDOM from 'react-dom/client'
|
|
@@ -226,320 +313,95 @@ if (!rootElement.innerHTML) {
|
|
|
226
313
|
}
|
|
227
314
|
\`\`\`
|
|
228
315
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
# Migration from React Location
|
|
232
|
-
|
|
233
|
-
Before you begin your journey in migrating from React Location, it's important that you have a good understanding of the [Routing Concepts](../routing/routing-concepts.md) and [Design Decisions](../decisions-on-dx.md) used by TanStack Router.
|
|
234
|
-
|
|
235
|
-
## Differences between React Location and TanStack Router
|
|
236
|
-
|
|
237
|
-
React Location and TanStack Router share much of same design decisions concepts, but there are some key differences that you should be aware of.
|
|
238
|
-
|
|
239
|
-
- React Location uses _generics_ to infer types for routes, while TanStack Router uses _module declaration merging_ to infer types.
|
|
240
|
-
- Route configuration in React Location is done using a single array of route definitions, while in TanStack Router, route configuration is done using a tree of route definitions starting with the [root route](../routing/routing-concepts.md#the-root-route).
|
|
241
|
-
- [File-based routing](../routing/file-based-routing.md) is the recommended way to define routes in TanStack Router, while React Location only allows you to define routes in a single file using a code-based approach.
|
|
242
|
-
- TanStack Router does support a [code-based approach](../routing/code-based-routing.md) to defining routes, but it is not recommended for most use cases. You can read more about why, over here: [why is file-based routing the preferred way to define routes?](../decisions-on-dx.md#why-is-file-based-routing-the-preferred-way-to-define-routes)
|
|
243
|
-
|
|
244
|
-
## Migration guide
|
|
245
|
-
|
|
246
|
-
In this guide we'll go over the process of migrating the [React Location Basic example](https://github.com/TanStack/router/tree/react-location/examples/basic) over to TanStack Router using file-based routing, with the end goal of having the same functionality as the original example (styling and other non-routing related code will be omitted).
|
|
247
|
-
|
|
248
|
-
> [!TIP]
|
|
249
|
-
> To use a code-based approach for defining your routes, you can read the [code-based Routing](../routing/code-based-routing.md) guide.
|
|
250
|
-
|
|
251
|
-
### Step 1: Swap over to TanStack Router's dependencies
|
|
252
|
-
|
|
253
|
-
First, we need to install the dependencies for TanStack Router. For detailed installation instructions, see our [How to Install TanStack Router](../how-to/install.md) guide.
|
|
254
|
-
|
|
255
|
-
\`\`\`sh
|
|
256
|
-
npm install @tanstack/react-router @tanstack/router-devtools
|
|
257
|
-
\`\`\`
|
|
258
|
-
|
|
259
|
-
And remove the React Location dependencies.
|
|
316
|
+
# Solid
|
|
260
317
|
|
|
261
|
-
\`\`\`
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
\`\`\`
|
|
274
|
-
|
|
275
|
-
And add it to your \`vite.config.js\`:
|
|
276
|
-
|
|
277
|
-
\`\`\`js
|
|
278
|
-
import { defineConfig } from 'vite'
|
|
279
|
-
import react from '@vitejs/plugin-react'
|
|
280
|
-
import { tanstackRouter } from '@tanstack/router-plugin/vite'
|
|
318
|
+
\`\`\`tsx
|
|
319
|
+
/* @refresh reload */
|
|
320
|
+
import { render } from 'solid-js/web'
|
|
321
|
+
import {
|
|
322
|
+
Outlet,
|
|
323
|
+
RouterProvider,
|
|
324
|
+
Link,
|
|
325
|
+
createRouter,
|
|
326
|
+
createRoute,
|
|
327
|
+
createRootRoute,
|
|
328
|
+
} from '@tanstack/solid-router'
|
|
329
|
+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
|
|
281
330
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
331
|
+
const rootRoute = createRootRoute({
|
|
332
|
+
component: () => (
|
|
333
|
+
<>
|
|
334
|
+
<div class="p-2 flex gap-2">
|
|
335
|
+
<Link to="/" class="[&.active]:font-bold">
|
|
336
|
+
Home
|
|
337
|
+
</Link>{' '}
|
|
338
|
+
<Link to="/about" class="[&.active]:font-bold">
|
|
339
|
+
About
|
|
340
|
+
</Link>
|
|
341
|
+
</div>
|
|
342
|
+
<hr />
|
|
343
|
+
<Outlet />
|
|
344
|
+
<TanStackRouterDevtools />
|
|
345
|
+
</>
|
|
346
|
+
),
|
|
285
347
|
})
|
|
286
|
-
\`\`\`
|
|
287
|
-
|
|
288
|
-
However, if your application does not use Vite, you use one of our other [supported bundlers](../routing/file-based-routing.md#getting-started-with-file-based-routing), or you can use the \`@tanstack/router-cli\` package to watch for changes in your routes files and automatically update the routes configuration.
|
|
289
|
-
|
|
290
|
-
### Step 3: Add the file-based configuration file to your project
|
|
291
|
-
|
|
292
|
-
Create a \`tsr.config.json\` file in the root of your project with the following content:
|
|
293
|
-
|
|
294
|
-
\`\`\`json
|
|
295
|
-
{
|
|
296
|
-
"routesDirectory": "./src/routes",
|
|
297
|
-
"generatedRouteTree": "./src/routeTree.gen.ts"
|
|
298
|
-
}
|
|
299
|
-
\`\`\`
|
|
300
|
-
|
|
301
|
-
You can find the full list of options for the \`tsr.config.json\` file [here](../routing/file-based-routing.md).
|
|
302
348
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
\`\`\`sh
|
|
308
|
-
mkdir src/routes
|
|
309
|
-
\`\`\`
|
|
310
|
-
|
|
311
|
-
### Step 5: Create the root route file
|
|
312
|
-
|
|
313
|
-
\`\`\`tsx
|
|
314
|
-
// src/routes/__root.tsx
|
|
315
|
-
import { createRootRoute, Outlet, Link } from '@tanstack/react-router'
|
|
316
|
-
import { TanStackRouterDevtools } from '@tanstack/router-devtools'
|
|
317
|
-
|
|
318
|
-
export const Route = createRootRoute({
|
|
319
|
-
component: () => {
|
|
349
|
+
const indexRoute = createRoute({
|
|
350
|
+
getParentRoute: () => rootRoute,
|
|
351
|
+
path: '/',
|
|
352
|
+
component: function Index() {
|
|
320
353
|
return (
|
|
321
|
-
|
|
322
|
-
<
|
|
323
|
-
|
|
324
|
-
Home
|
|
325
|
-
</Link>
|
|
326
|
-
<Link to="/posts">Posts</Link>
|
|
327
|
-
</div>
|
|
328
|
-
<hr />
|
|
329
|
-
<Outlet />
|
|
330
|
-
<TanStackRouterDevtools />
|
|
331
|
-
</>
|
|
354
|
+
<div class="p-2">
|
|
355
|
+
<h3>Welcome Home!</h3>
|
|
356
|
+
</div>
|
|
332
357
|
)
|
|
333
358
|
},
|
|
334
359
|
})
|
|
335
|
-
\`\`\`
|
|
336
|
-
|
|
337
|
-
### Step 6: Create the index route file
|
|
338
|
-
|
|
339
|
-
\`\`\`tsx
|
|
340
|
-
// src/routes/index.tsx
|
|
341
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
342
360
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
> You will need to move any related components and logic needed for the index route from the \`src/index.tsx\` file to the \`src/routes/index.tsx\` file.
|
|
349
|
-
|
|
350
|
-
### Step 7: Create the posts route file
|
|
351
|
-
|
|
352
|
-
\`\`\`tsx
|
|
353
|
-
// src/routes/posts.tsx
|
|
354
|
-
import { createFileRoute, Link, Outlet } from '@tanstack/react-router'
|
|
355
|
-
|
|
356
|
-
export const Route = createFileRoute('/posts')({
|
|
357
|
-
component: Posts,
|
|
358
|
-
loader: async () => {
|
|
359
|
-
const posts = await fetchPosts()
|
|
360
|
-
return {
|
|
361
|
-
posts,
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
function Posts() {
|
|
367
|
-
const { posts } = Route.useLoaderData()
|
|
368
|
-
return (
|
|
369
|
-
<div>
|
|
370
|
-
<nav>
|
|
371
|
-
{posts.map((post) => (
|
|
372
|
-
<Link
|
|
373
|
-
key={post.id}
|
|
374
|
-
to={\`/posts/$postId\`}
|
|
375
|
-
params={{ postId: post.id }}
|
|
376
|
-
>
|
|
377
|
-
{post.title}
|
|
378
|
-
</Link>
|
|
379
|
-
))}
|
|
380
|
-
</nav>
|
|
381
|
-
<Outlet />
|
|
382
|
-
</div>
|
|
383
|
-
)
|
|
384
|
-
}
|
|
385
|
-
\`\`\`
|
|
386
|
-
|
|
387
|
-
> You will need to move any related components and logic needed for the posts route from the \`src/index.tsx\` file to the \`src/routes/posts.tsx\` file.
|
|
388
|
-
|
|
389
|
-
### Step 8: Create the posts index route file
|
|
390
|
-
|
|
391
|
-
\`\`\`tsx
|
|
392
|
-
// src/routes/posts.index.tsx
|
|
393
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
394
|
-
|
|
395
|
-
export const Route = createFileRoute('/posts/')({
|
|
396
|
-
component: PostsIndex,
|
|
397
|
-
})
|
|
398
|
-
\`\`\`
|
|
399
|
-
|
|
400
|
-
> You will need to move any related components and logic needed for the posts index route from the \`src/index.tsx\` file to the \`src/routes/posts.index.tsx\` file.
|
|
401
|
-
|
|
402
|
-
### Step 9: Create the posts id route file
|
|
403
|
-
|
|
404
|
-
\`\`\`tsx
|
|
405
|
-
// src/routes/posts.$postId.tsx
|
|
406
|
-
import { createFileRoute } from '@tanstack/react-router'
|
|
407
|
-
|
|
408
|
-
export const Route = createFileRoute('/posts/$postId')({
|
|
409
|
-
component: PostsId,
|
|
410
|
-
loader: async ({ params: { postId } }) => {
|
|
411
|
-
const post = await fetchPost(postId)
|
|
412
|
-
return {
|
|
413
|
-
post,
|
|
414
|
-
}
|
|
361
|
+
const aboutRoute = createRoute({
|
|
362
|
+
getParentRoute: () => rootRoute,
|
|
363
|
+
path: '/about',
|
|
364
|
+
component: function About() {
|
|
365
|
+
return <div class="p-2">Hello from About!</div>
|
|
415
366
|
},
|
|
416
367
|
})
|
|
417
368
|
|
|
418
|
-
|
|
419
|
-
const { post } = Route.useLoaderData()
|
|
420
|
-
// ...
|
|
421
|
-
}
|
|
422
|
-
\`\`\`
|
|
423
|
-
|
|
424
|
-
> You will need to move any related components and logic needed for the posts id route from the \`src/index.tsx\` file to the \`src/routes/posts.$postId.tsx\` file.
|
|
425
|
-
|
|
426
|
-
### Step 10: Generate the route tree
|
|
427
|
-
|
|
428
|
-
If you are using one of the supported bundlers, the route tree will be generated automatically when you run the dev script.
|
|
429
|
-
|
|
430
|
-
If you are not using one of the supported bundlers, you can generate the route tree by running the following command:
|
|
431
|
-
|
|
432
|
-
\`\`\`sh
|
|
433
|
-
npx tsr generate
|
|
434
|
-
\`\`\`
|
|
435
|
-
|
|
436
|
-
### Step 11: Update the main entry file to render the Router
|
|
437
|
-
|
|
438
|
-
Once you've generated the route-tree, you can then update the \`src/index.tsx\` file to create the router instance and render it.
|
|
439
|
-
|
|
440
|
-
\`\`\`tsx
|
|
441
|
-
// src/index.tsx
|
|
442
|
-
import React from 'react'
|
|
443
|
-
import ReactDOM from 'react-dom'
|
|
444
|
-
import { createRouter, RouterProvider } from '@tanstack/react-router'
|
|
445
|
-
|
|
446
|
-
// Import the generated route tree
|
|
447
|
-
import { routeTree } from './routeTree.gen'
|
|
369
|
+
const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
|
|
448
370
|
|
|
449
|
-
// Create a new router instance
|
|
450
371
|
const router = createRouter({ routeTree })
|
|
451
372
|
|
|
452
|
-
|
|
453
|
-
declare module '@tanstack/react-router' {
|
|
373
|
+
declare module '@tanstack/solid-router' {
|
|
454
374
|
interface Register {
|
|
455
375
|
router: typeof router
|
|
456
376
|
}
|
|
457
377
|
}
|
|
458
378
|
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
// Render the app
|
|
462
|
-
const rootElement = document.getElementById(domElementId)
|
|
463
|
-
if (!rootElement) {
|
|
464
|
-
throw new Error(\`Element with id \${domElementId} not found\`)
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
ReactDOM.createRoot(rootElement).render(
|
|
468
|
-
<React.StrictMode>
|
|
469
|
-
<RouterProvider router={router} />
|
|
470
|
-
</React.StrictMode>,
|
|
471
|
-
)
|
|
379
|
+
const rootElement = document.getElementById('app')!
|
|
380
|
+
render(() => <RouterProvider router={router} />, rootElement)
|
|
472
381
|
\`\`\`
|
|
473
382
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
You should now have successfully migrated your application from React Location to TanStack Router using file-based routing.
|
|
477
|
-
|
|
478
|
-
React Location also has a few more features that you might be using in your application. Here are some guides to help you migrate those features:
|
|
479
|
-
|
|
480
|
-
- [Search params](../guide/search-params.md)
|
|
481
|
-
- [Data loading](../guide/data-loading.md)
|
|
482
|
-
- [History types](../guide/history-types.md)
|
|
483
|
-
- [Wildcard / Splat / Catch-all routes](../routing/routing-concepts.md#splat--catch-all-routes)
|
|
484
|
-
- [Authenticated routes](../guide/authenticated-routes.md)
|
|
485
|
-
|
|
486
|
-
TanStack Router also has a few more features that you might want to explore:
|
|
487
|
-
|
|
488
|
-
- [Router Context](../guide/router-context.md)
|
|
489
|
-
- [Preloading](../guide/preloading.md)
|
|
490
|
-
- [Pathless Layout Routes](../routing/routing-concepts.md#pathless-layout-routes)
|
|
491
|
-
- [Route masking](../guide/route-masking.md)
|
|
492
|
-
- [SSR](../guide/ssr.md)
|
|
493
|
-
- ... and more!
|
|
494
|
-
|
|
495
|
-
If you are facing any issues or have any questions, feel free to ask for help in the TanStack Discord.
|
|
496
|
-
|
|
497
|
-
# Migration from React Router Checklist
|
|
498
|
-
|
|
499
|
-
**_If your UI is blank, open the console, and you will probably have some errors that read something along the lines of \`cannot use 'useNavigate' outside of context\` . This means there are React Router api’s that are still imported and referenced that you need to find and remove. The easiest way to make sure you find all React Router imports is to uninstall \`react-router-dom\` and then you should get typescript errors in your files. Then you will know what to change to a \`@tanstack/react-router\` import._**
|
|
500
|
-
|
|
501
|
-
Here is the [example repo](https://github.com/Benanna2019/SickFitsForEveryone/tree/migrate-to-tanstack/router/React-Router)
|
|
502
|
-
|
|
503
|
-
- [ ] Install Router - \`npm i @tanstack/react-router\` (see [detailed installation guide](../how-to/install.md))
|
|
504
|
-
- [ ] **Optional:** Uninstall React Router to get TypeScript errors on imports.
|
|
505
|
-
- At this point I don’t know if you can do a gradual migration, but it seems likely you could have multiple router providers, not desirable.
|
|
506
|
-
- The api’s between React Router and TanStack Router are very similar and could most likely be handled in a sprint cycle or two if that is your companies way of doing things.
|
|
507
|
-
- [ ] Create Routes for each existing React Router route we have
|
|
508
|
-
- [ ] Create root route
|
|
509
|
-
- [ ] Create router instance
|
|
510
|
-
- [ ] Add global module in main.tsx
|
|
511
|
-
- [ ] Remove any React Router (\`createBrowserRouter\` or \`BrowserRouter\`), \`Routes\`, and \`Route\` Components from main.tsx
|
|
512
|
-
- [ ] **Optional:** Refactor \`render\` function for custom setup/providers - The repo referenced above has an example - This was necessary in the case of Supertokens. Supertoken has a specific setup with React Router and a different setup with all other React implementations
|
|
513
|
-
- [ ] Set RouterProvider and pass it the router as the prop
|
|
514
|
-
- [ ] Replace all instances of React Router \`Link\` component with \`@tanstack/react-router\` \`Link\` component
|
|
515
|
-
- [ ] Add \`to\` prop with literal path
|
|
516
|
-
- [ ] Add \`params\` prop, where necessary with params like so \`params={{ orderId: order.id }}\`
|
|
517
|
-
- [ ] Replace all instances of React Router \`useNavigate\` hook with \`@tanstack/react-router\` \`useNavigate\` hook
|
|
518
|
-
- [ ] Set \`to\` property and \`params\` property where needed
|
|
519
|
-
- [ ] Replace any React Router \`Outlet\`'s with the \`@tanstack/react-router\` equivalent
|
|
520
|
-
- [ ] If you are using \`useSearchParams\` hook from React Router, move the search params default value to the validateSearch property on a Route definition.
|
|
521
|
-
- [ ] Instead of using the \`useSearchParams\` hook, use \`@tanstack/react-router\` \`Link\`'s search property to update the search params state
|
|
522
|
-
- [ ] To read search params you can do something like the following
|
|
523
|
-
- \`const { page } = useSearch({ from: productPage.fullPath })\`
|
|
524
|
-
- [ ] If using React Router’s \`useParams\` hook, update the import to be from \`@tanstack/react-router\` and set the \`from\` property to the literal path name where you want to read the params object from
|
|
525
|
-
- So say we have a route with the path name \`orders/$orderid\`.
|
|
526
|
-
- In the \`useParams\` hook we would set up our hook like so: \`const params = useParams({ from: "/orders/$orderId" })\`
|
|
527
|
-
- Then wherever we wanted to access the order id we would get it off of the params object \`params.orderId\`
|
|
383
|
+
<!-- ::end:framework -->
|
|
528
384
|
|
|
529
|
-
|
|
385
|
+
If you glossed over these examples or didn't understand something, we don't blame you, because there's so much more to learn to really take advantage of TanStack Router! Let's move on.
|
|
530
386
|
|
|
531
|
-
|
|
387
|
+
# Installation with Esbuild
|
|
532
388
|
|
|
533
389
|
To use file-based routing with **Esbuild**, you'll need to install the \`@tanstack/router-plugin\` package.
|
|
534
390
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
391
|
+
<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
|
|
392
|
+
|
|
393
|
+
react: @tanstack/router-plugin
|
|
394
|
+
solid: @tanstack/router-plugin
|
|
395
|
+
|
|
396
|
+
<!-- ::end:tabs -->
|
|
538
397
|
|
|
539
398
|
Once installed, you'll need to add the plugin to your configuration.
|
|
540
399
|
|
|
541
|
-
|
|
542
|
-
|
|
400
|
+
<!-- ::start:framework -->
|
|
401
|
+
|
|
402
|
+
# React
|
|
403
|
+
|
|
404
|
+
\`\`\`ts title="esbuild.config.js"
|
|
543
405
|
import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
|
|
544
406
|
|
|
545
407
|
export default {
|
|
@@ -555,9 +417,44 @@ export default {
|
|
|
555
417
|
|
|
556
418
|
Or, you can clone our [Quickstart Esbuild example](https://github.com/TanStack/router/tree/main/examples/react/quickstart-esbuild-file-based) and get started.
|
|
557
419
|
|
|
558
|
-
|
|
420
|
+
# Solid
|
|
421
|
+
|
|
422
|
+
\`\`\`ts title="build.js"
|
|
423
|
+
import * as esbuild from 'esbuild'
|
|
424
|
+
import { solidPlugin } from 'esbuild-plugin-solid'
|
|
425
|
+
import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
|
|
426
|
+
|
|
427
|
+
const isDev = process.argv.includes('--dev')
|
|
428
|
+
|
|
429
|
+
const ctx = await esbuild.context({
|
|
430
|
+
entryPoints: ['src/main.tsx'],
|
|
431
|
+
outfile: 'dist/main.js',
|
|
432
|
+
minify: !isDev,
|
|
433
|
+
bundle: true,
|
|
434
|
+
format: 'esm',
|
|
435
|
+
target: ['esnext'],
|
|
436
|
+
sourcemap: true,
|
|
437
|
+
plugins: [
|
|
438
|
+
solidPlugin(),
|
|
439
|
+
tanstackRouter({ target: 'solid', autoCodeSplitting: true }),
|
|
440
|
+
],
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
if (isDev) {
|
|
444
|
+
await ctx.watch()
|
|
445
|
+
const { host, port } = await ctx.serve({ servedir: '.', port: 3005 })
|
|
446
|
+
console.log(\`Server running at http://\${host || 'localhost'}:\${port}\`)
|
|
447
|
+
} else {
|
|
448
|
+
await ctx.rebuild()
|
|
449
|
+
await ctx.dispose()
|
|
450
|
+
}
|
|
451
|
+
\`\`\`
|
|
452
|
+
|
|
453
|
+
Or, you can clone our [Quickstart Esbuild example](https://github.com/TanStack/router/tree/main/examples/solid/quickstart-esbuild-file-based) and get started.
|
|
559
454
|
|
|
560
|
-
|
|
455
|
+
<!-- ::end:framework -->
|
|
456
|
+
|
|
457
|
+
Now that you've added the plugin to your Esbuild configuration, you're all set to start using file-based routing with TanStack Router.
|
|
561
458
|
|
|
562
459
|
## Ignoring the generated route tree file
|
|
563
460
|
|
|
@@ -605,7 +502,7 @@ When using the TanStack Router Plugin with Esbuild for File-based routing, it co
|
|
|
605
502
|
|
|
606
503
|
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.
|
|
607
504
|
|
|
608
|
-
You can find all the available configuration options in the [File-based Routing API Reference](
|
|
505
|
+
You can find all the available configuration options in the [File-based Routing API Reference](../api/file-based-routing.md).
|
|
609
506
|
|
|
610
507
|
# Installation with Router CLI
|
|
611
508
|
|
|
@@ -614,9 +511,12 @@ You can find all the available configuration options in the [File-based Routing
|
|
|
614
511
|
|
|
615
512
|
To use file-based routing with the TanStack Router CLI, you'll need to install the \`@tanstack/router-cli\` package.
|
|
616
513
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
514
|
+
<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
|
|
515
|
+
|
|
516
|
+
react: @tanstack/router-cli
|
|
517
|
+
solid: @tanstack/router-cli
|
|
518
|
+
|
|
519
|
+
<!-- ::end:tabs -->
|
|
620
520
|
|
|
621
521
|
Once installed, you'll need to amend your scripts in your \`package.json\` for the CLI to \`watch\` and \`generate\` files.
|
|
622
522
|
|
|
@@ -631,6 +531,25 @@ Once installed, you'll need to amend your scripts in your \`package.json\` for t
|
|
|
631
531
|
}
|
|
632
532
|
\`\`\`
|
|
633
533
|
|
|
534
|
+
<!-- ::start:framework -->
|
|
535
|
+
|
|
536
|
+
# Solid
|
|
537
|
+
|
|
538
|
+
If you are using TypeScript, you should also add the following options to your \`tsconfig.json\`:
|
|
539
|
+
|
|
540
|
+
\`\`\`json
|
|
541
|
+
{
|
|
542
|
+
"compilerOptions": {
|
|
543
|
+
"jsx": "preserve",
|
|
544
|
+
"jsxImportSource": "solid-js"
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
\`\`\`
|
|
548
|
+
|
|
549
|
+
With that, you're all set to start using file-based routing with TanStack Router.
|
|
550
|
+
|
|
551
|
+
<!-- ::end:framework -->
|
|
552
|
+
|
|
634
553
|
[//]: # 'AfterScripts'
|
|
635
554
|
[//]: # 'AfterScripts'
|
|
636
555
|
|
|
@@ -693,36 +612,56 @@ You can use those settings either at a user level or only for a single workspace
|
|
|
693
612
|
|
|
694
613
|
When using the TanStack Router CLI for File-based routing, it comes with some sane defaults that should work for most projects:
|
|
695
614
|
|
|
615
|
+
<!-- ::start:framework -->
|
|
616
|
+
|
|
617
|
+
# React
|
|
618
|
+
|
|
696
619
|
\`\`\`json
|
|
697
620
|
{
|
|
698
621
|
"routesDirectory": "./src/routes",
|
|
699
622
|
"generatedRouteTree": "./src/routeTree.gen.ts",
|
|
700
623
|
"routeFileIgnorePrefix": "-",
|
|
701
|
-
"quoteStyle": "single"
|
|
624
|
+
"quoteStyle": "single",
|
|
625
|
+
"target": "react"
|
|
702
626
|
}
|
|
703
627
|
\`\`\`
|
|
704
628
|
|
|
705
|
-
|
|
629
|
+
# Solid
|
|
706
630
|
|
|
707
|
-
|
|
708
|
-
|
|
631
|
+
\`\`\`json
|
|
632
|
+
{
|
|
633
|
+
"routesDirectory": "./src/routes",
|
|
634
|
+
"generatedRouteTree": "./src/routeTree.gen.ts",
|
|
635
|
+
"routeFileIgnorePrefix": "-",
|
|
636
|
+
"quoteStyle": "single",
|
|
637
|
+
"target": "solid"
|
|
638
|
+
}
|
|
639
|
+
\`\`\`
|
|
709
640
|
|
|
710
|
-
|
|
641
|
+
<!-- ::end:framework -->
|
|
711
642
|
|
|
712
|
-
|
|
643
|
+
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 creating a \`tsr.config.json\` file in the root of your project directory.
|
|
644
|
+
|
|
645
|
+
You can find all the available configuration options in the [File-based Routing API Reference](../api/file-based-routing.md).
|
|
713
646
|
|
|
714
|
-
|
|
647
|
+
# Installation with Rspack
|
|
715
648
|
|
|
716
649
|
To use file-based routing with **Rspack** or **Rsbuild**, you'll need to install the \`@tanstack/router-plugin\` package.
|
|
717
650
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
651
|
+
<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
|
|
652
|
+
|
|
653
|
+
react: @tanstack/router-plugin
|
|
654
|
+
solid: @tanstack/router-plugin
|
|
655
|
+
|
|
656
|
+
<!-- ::end:tabs -->
|
|
721
657
|
|
|
722
658
|
Once installed, you'll need to add the plugin to your configuration.
|
|
723
659
|
|
|
724
|
-
|
|
725
|
-
|
|
660
|
+
<!-- ::start:framework -->
|
|
661
|
+
|
|
662
|
+
# React
|
|
663
|
+
|
|
664
|
+
\`\`\`ts title="rsbuild.config.ts"
|
|
726
665
|
import { defineConfig } from '@rsbuild/core'
|
|
727
666
|
import { pluginReact } from '@rsbuild/plugin-react'
|
|
728
667
|
import { tanstackRouter } from '@tanstack/router-plugin/rspack'
|
|
@@ -744,9 +683,34 @@ export default defineConfig({
|
|
|
744
683
|
|
|
745
684
|
Or, you can clone our [Quickstart Rspack/Rsbuild example](https://github.com/TanStack/router/tree/main/examples/react/quickstart-rspack-file-based) and get started.
|
|
746
685
|
|
|
747
|
-
|
|
686
|
+
# Solid
|
|
687
|
+
|
|
688
|
+
\`\`\`ts title="rsbuild.config.ts"
|
|
689
|
+
import { defineConfig } from '@rsbuild/core'
|
|
690
|
+
import { pluginBabel } from '@rsbuild/plugin-babel'
|
|
691
|
+
import { pluginSolid } from '@rsbuild/plugin-solid'
|
|
692
|
+
import { tanstackRouter } from '@tanstack/router-plugin/rspack'
|
|
693
|
+
|
|
694
|
+
export default defineConfig({
|
|
695
|
+
plugins: [
|
|
696
|
+
pluginBabel({
|
|
697
|
+
include: /\.(?:jsx|tsx)$/,
|
|
698
|
+
}),
|
|
699
|
+
pluginSolid(),
|
|
700
|
+
],
|
|
701
|
+
tools: {
|
|
702
|
+
rspack: {
|
|
703
|
+
plugins: [tanstackRouter({ target: 'solid', autoCodeSplitting: true })],
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
})
|
|
707
|
+
\`\`\`
|
|
708
|
+
|
|
709
|
+
Or, you can clone our [Quickstart Rspack/Rsbuild example](https://github.com/TanStack/router/tree/main/examples/solid/quickstart-rspack-file-based) and get started.
|
|
748
710
|
|
|
749
|
-
|
|
711
|
+
<!-- ::end:framework -->
|
|
712
|
+
|
|
713
|
+
Now that you've added the plugin to your Rspack/Rsbuild configuration, you're all set to start using file-based routing with TanStack Router.
|
|
750
714
|
|
|
751
715
|
## Ignoring the generated route tree file
|
|
752
716
|
|
|
@@ -794,22 +758,26 @@ When using the TanStack Router Plugin with Rspack (or Rsbuild) for File-based ro
|
|
|
794
758
|
|
|
795
759
|
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.
|
|
796
760
|
|
|
797
|
-
You can find all the available configuration options in the [File-based Routing API Reference](
|
|
761
|
+
You can find all the available configuration options in the [File-based Routing API Reference](../api/file-based-routing.md).
|
|
798
762
|
|
|
799
763
|
# Installation with Vite
|
|
800
764
|
|
|
801
|
-
[//]: # 'BundlerConfiguration'
|
|
802
|
-
|
|
803
765
|
To use file-based routing with **Vite**, you'll need to install the \`@tanstack/router-plugin\` package.
|
|
804
766
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
767
|
+
<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
|
|
768
|
+
|
|
769
|
+
react: @tanstack/router-plugin
|
|
770
|
+
solid: @tanstack/router-plugin
|
|
771
|
+
|
|
772
|
+
<!-- ::end:tabs -->
|
|
808
773
|
|
|
809
774
|
Once installed, you'll need to add the plugin to your Vite configuration.
|
|
810
775
|
|
|
811
|
-
|
|
812
|
-
|
|
776
|
+
<!-- ::start:framework -->
|
|
777
|
+
|
|
778
|
+
# React
|
|
779
|
+
|
|
780
|
+
\`\`\`ts title="vite.config.ts"
|
|
813
781
|
import { defineConfig } from 'vite'
|
|
814
782
|
import react from '@vitejs/plugin-react'
|
|
815
783
|
import { tanstackRouter } from '@tanstack/router-plugin/vite'
|
|
@@ -830,12 +798,31 @@ export default defineConfig({
|
|
|
830
798
|
|
|
831
799
|
Or, you can clone our [Quickstart Vite example](https://github.com/TanStack/router/tree/main/examples/react/quickstart-file-based) and get started.
|
|
832
800
|
|
|
833
|
-
|
|
834
|
-
> If you are using the older \`@tanstack/router-vite-plugin\` package, you can still continue to use it, as it will be aliased to the \`@tanstack/router-plugin/vite\` package. However, we would recommend using the \`@tanstack/router-plugin\` package directly.
|
|
801
|
+
# Solid
|
|
835
802
|
|
|
836
|
-
|
|
803
|
+
\`\`\`ts title="vite.config.ts"
|
|
804
|
+
import { defineConfig } from 'vite'
|
|
805
|
+
import solid from 'vite-plugin-solid'
|
|
806
|
+
import { tanstackRouter } from '@tanstack/router-plugin/vite'
|
|
837
807
|
|
|
838
|
-
|
|
808
|
+
// https://vitejs.dev/config/
|
|
809
|
+
export default defineConfig({
|
|
810
|
+
plugins: [
|
|
811
|
+
tanstackRouter({
|
|
812
|
+
target: 'solid',
|
|
813
|
+
autoCodeSplitting: true,
|
|
814
|
+
}),
|
|
815
|
+
solid(),
|
|
816
|
+
// ...
|
|
817
|
+
],
|
|
818
|
+
})
|
|
819
|
+
\`\`\`
|
|
820
|
+
|
|
821
|
+
Or, you can clone our [Quickstart Vite example](https://github.com/TanStack/router/tree/main/examples/solid/quickstart-file-based) and get started.
|
|
822
|
+
|
|
823
|
+
<!-- ::end:framework -->
|
|
824
|
+
|
|
825
|
+
Now that you've added the plugin to your Vite configuration, you're all set to start using file-based routing with TanStack Router.
|
|
839
826
|
|
|
840
827
|
## Ignoring the generated route tree file
|
|
841
828
|
|
|
@@ -883,22 +870,26 @@ When using the TanStack Router Plugin with Vite for File-based routing, it comes
|
|
|
883
870
|
|
|
884
871
|
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.
|
|
885
872
|
|
|
886
|
-
You can find all the available configuration options in the [File-based Routing API Reference](
|
|
873
|
+
You can find all the available configuration options in the [File-based Routing API Reference](../api/file-based-routing.md).
|
|
887
874
|
|
|
888
875
|
# Installation with Webpack
|
|
889
876
|
|
|
890
|
-
[//]: # 'BundlerConfiguration'
|
|
891
|
-
|
|
892
877
|
To use file-based routing with **Webpack**, you'll need to install the \`@tanstack/router-plugin\` package.
|
|
893
878
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
879
|
+
<!-- ::start:tabs variant="package-manager" mode="dev-install" -->
|
|
880
|
+
|
|
881
|
+
react: @tanstack/router-plugin
|
|
882
|
+
solid: @tanstack/router-plugin
|
|
883
|
+
|
|
884
|
+
<!-- ::end:tabs -->
|
|
897
885
|
|
|
898
886
|
Once installed, you'll need to add the plugin to your configuration.
|
|
899
887
|
|
|
900
|
-
|
|
901
|
-
|
|
888
|
+
<!-- ::start:framework -->
|
|
889
|
+
|
|
890
|
+
# React
|
|
891
|
+
|
|
892
|
+
\`\`\`ts title="webpack.config.ts"
|
|
902
893
|
import { tanstackRouter } from '@tanstack/router-plugin/webpack'
|
|
903
894
|
|
|
904
895
|
export default {
|
|
@@ -913,9 +904,37 @@ export default {
|
|
|
913
904
|
|
|
914
905
|
Or, you can clone our [Quickstart Webpack example](https://github.com/TanStack/router/tree/main/examples/react/quickstart-webpack-file-based) and get started.
|
|
915
906
|
|
|
916
|
-
|
|
907
|
+
# Solid
|
|
917
908
|
|
|
918
|
-
|
|
909
|
+
\`\`\`ts title="webpack.config.ts"
|
|
910
|
+
import { tanstackRouter } from '@tanstack/router-plugin/webpack'
|
|
911
|
+
|
|
912
|
+
export default {
|
|
913
|
+
plugins: [
|
|
914
|
+
tanstackRouter({
|
|
915
|
+
target: 'solid',
|
|
916
|
+
autoCodeSplitting: true,
|
|
917
|
+
}),
|
|
918
|
+
],
|
|
919
|
+
}
|
|
920
|
+
\`\`\`
|
|
921
|
+
|
|
922
|
+
And in the .babelrc (SWC doesn't support solid-js, see [here](https://www.answeroverflow.com/m/1135200483116593182)), add these presets:
|
|
923
|
+
|
|
924
|
+
\`\`\`tsx
|
|
925
|
+
// .babelrc
|
|
926
|
+
|
|
927
|
+
{
|
|
928
|
+
"presets": ["babel-preset-solid", "@babel/preset-typescript"]
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
\`\`\`
|
|
932
|
+
|
|
933
|
+
Or, for a full webpack.config.js, you can clone our [Quickstart Webpack example](https://github.com/TanStack/router/tree/main/examples/solid/quickstart-webpack-file-based) and get started.
|
|
934
|
+
|
|
935
|
+
<!-- ::end:framework -->
|
|
936
|
+
|
|
937
|
+
Now that you've added the plugin to your Webpack configuration, you're all set to start using file-based routing with TanStack Router.
|
|
919
938
|
|
|
920
939
|
## Ignoring the generated route tree file
|
|
921
940
|
|
|
@@ -963,6 +982,6 @@ When using the TanStack Router Plugin with Webpack for File-based routing, it co
|
|
|
963
982
|
|
|
964
983
|
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.
|
|
965
984
|
|
|
966
|
-
You can find all the available configuration options in the [File-based Routing API Reference](
|
|
985
|
+
You can find all the available configuration options in the [File-based Routing API Reference](../api/file-based-routing.md).
|
|
967
986
|
|
|
968
987
|
`;
|