@tanstack/react-router 0.0.1-alpha.0 → 0.0.1-alpha.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/build/stats-html.html +1 -1
- package/build/stats-react.json +25 -25
- package/package.json +5 -5
- package/build/cjs/index.js +0 -364
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/location-core/build/esm/index.js +0 -2214
- package/build/cjs/location-core/build/esm/index.js.map +0 -1
- package/build/cjs/react-location/src/index.js +0 -311
- package/build/cjs/react-location/src/index.js.map +0 -1
- package/build/cjs/src/index.js +0 -335
- package/build/cjs/src/index.js.map +0 -1
- package/build/types/createRoutes.test.d.ts +0 -0
- package/build/types/qss.d.ts +0 -2
- package/src/createRoutes.test.tsx +0 -310
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
// import * as React from 'react'
|
|
2
|
-
// import { z } from 'zod'
|
|
3
|
-
// import { createRoutes, Router, RoutesInfo, Link } from '.'
|
|
4
|
-
|
|
5
|
-
// const paramTest = createRoutes().addChildren((createRoute) => [
|
|
6
|
-
// createRoute({
|
|
7
|
-
// path: ':a1',
|
|
8
|
-
// loader: async ({ params }) => {
|
|
9
|
-
// params.a1
|
|
10
|
-
// return {}
|
|
11
|
-
// },
|
|
12
|
-
// }).addChildren((createRoute) => [
|
|
13
|
-
// createRoute({
|
|
14
|
-
// path: ':a2',
|
|
15
|
-
// loader: async ({ params }) => {
|
|
16
|
-
// params.a1
|
|
17
|
-
// params.a2
|
|
18
|
-
// return {}
|
|
19
|
-
// },
|
|
20
|
-
// }),
|
|
21
|
-
// createRoute({
|
|
22
|
-
// path: ':a3',
|
|
23
|
-
// loader: async ({ params }) => {
|
|
24
|
-
// params.a1
|
|
25
|
-
// params.a3
|
|
26
|
-
// return {
|
|
27
|
-
// params,
|
|
28
|
-
// }
|
|
29
|
-
// },
|
|
30
|
-
// }),
|
|
31
|
-
// ]),
|
|
32
|
-
// createRoute({
|
|
33
|
-
// path: ':b1',
|
|
34
|
-
// loader: async ({ params }) => {
|
|
35
|
-
// params.b1
|
|
36
|
-
// return {}
|
|
37
|
-
// },
|
|
38
|
-
// }).addChildren((createRoute) => [
|
|
39
|
-
// createRoute({
|
|
40
|
-
// path: ':b2',
|
|
41
|
-
// loader: async ({ params }) => {
|
|
42
|
-
// params.b1
|
|
43
|
-
// params.b2
|
|
44
|
-
// return {}
|
|
45
|
-
// },
|
|
46
|
-
// }),
|
|
47
|
-
// ]),
|
|
48
|
-
// ])
|
|
49
|
-
|
|
50
|
-
// const searchSchemaTest = createRoutes({
|
|
51
|
-
// searchSchema: {
|
|
52
|
-
// userId: z.string(),
|
|
53
|
-
// },
|
|
54
|
-
// loader: async ({ search }) => {
|
|
55
|
-
// search.userId
|
|
56
|
-
// return {}
|
|
57
|
-
// },
|
|
58
|
-
// }).addChildren((createRoute) => [
|
|
59
|
-
// createRoute({
|
|
60
|
-
// path: '/',
|
|
61
|
-
// }),
|
|
62
|
-
// createRoute({
|
|
63
|
-
// path: 'dashboard',
|
|
64
|
-
// searchSchema: {
|
|
65
|
-
// version: z.string(),
|
|
66
|
-
// dateRange: z.tuple([z.number(), z.number()]).optional(),
|
|
67
|
-
// },
|
|
68
|
-
// loader: async ({ search }) => {
|
|
69
|
-
// search.userId, search.dateRange, search.version
|
|
70
|
-
|
|
71
|
-
// return {
|
|
72
|
-
// invoices: 'invoices' as const,
|
|
73
|
-
// }
|
|
74
|
-
// },
|
|
75
|
-
// }).addChildren((createRoute) => [
|
|
76
|
-
// createRoute({
|
|
77
|
-
// path: 'invoices',
|
|
78
|
-
// }).addChildren((createRoute) => [
|
|
79
|
-
// createRoute({
|
|
80
|
-
// path: '/',
|
|
81
|
-
// loader: async ({ search }) => {
|
|
82
|
-
// return {
|
|
83
|
-
// invoices: 'invoices' as const,
|
|
84
|
-
// }
|
|
85
|
-
// },
|
|
86
|
-
// action: async (partialInvoice: 'partialInvoince', ctx) => {
|
|
87
|
-
// const invoice = await Promise.resolve(
|
|
88
|
-
// `postInvoice(${partialInvoice})`,
|
|
89
|
-
// )
|
|
90
|
-
|
|
91
|
-
// // // Redirect to the new invoice
|
|
92
|
-
// // ctx.router.navigate({
|
|
93
|
-
// // to: invoice,
|
|
94
|
-
// // // Use the current match for relative paths
|
|
95
|
-
// // from: ctx.match.pathname,
|
|
96
|
-
// // })
|
|
97
|
-
|
|
98
|
-
// return invoice
|
|
99
|
-
// },
|
|
100
|
-
// }),
|
|
101
|
-
// createRoute({
|
|
102
|
-
// path: ':invoiceId',
|
|
103
|
-
// loader: async ({ params, search }) => {
|
|
104
|
-
// return {
|
|
105
|
-
// invoice: `fetchInvoiceById(${params.invoiceId}!)`,
|
|
106
|
-
// }
|
|
107
|
-
// },
|
|
108
|
-
// action: (invoice: 'invoice') =>
|
|
109
|
-
// Promise.resolve('invoiceResponse' as const),
|
|
110
|
-
// }),
|
|
111
|
-
// ]),
|
|
112
|
-
// createRoute({
|
|
113
|
-
// path: 'users',
|
|
114
|
-
// loader: async () => {
|
|
115
|
-
// return {
|
|
116
|
-
// users: 'fetchUsers()',
|
|
117
|
-
// }
|
|
118
|
-
// },
|
|
119
|
-
// preSearchFilters: [
|
|
120
|
-
// // Keep the usersView search param around
|
|
121
|
-
// // while in this route (or it's children!)
|
|
122
|
-
// (search) => ({
|
|
123
|
-
// ...search,
|
|
124
|
-
// hello: true,
|
|
125
|
-
// }),
|
|
126
|
-
// ],
|
|
127
|
-
// }).addChildren((createRoute) => [
|
|
128
|
-
// createRoute({
|
|
129
|
-
// path: ':userId',
|
|
130
|
-
// loader: async ({ params }) => {
|
|
131
|
-
// return {
|
|
132
|
-
// user: `fetchUserById(${params.userId}!)`,
|
|
133
|
-
// }
|
|
134
|
-
// },
|
|
135
|
-
// }),
|
|
136
|
-
// ]),
|
|
137
|
-
// ]),
|
|
138
|
-
// createRoute({
|
|
139
|
-
// // Your elements can be asynchronous, which means you can code-split!
|
|
140
|
-
// path: 'expensive',
|
|
141
|
-
// }),
|
|
142
|
-
// createRoute({
|
|
143
|
-
// path: 'authenticated/',
|
|
144
|
-
// }).addChildren((createRoute) => [
|
|
145
|
-
// createRoute({
|
|
146
|
-
// path: '/',
|
|
147
|
-
// // element: <Authenticated />,
|
|
148
|
-
// }),
|
|
149
|
-
// ]),
|
|
150
|
-
// ])
|
|
151
|
-
|
|
152
|
-
// type MyRoutesInfo = RoutesInfo<typeof searchSchemaTest>
|
|
153
|
-
// // ^?
|
|
154
|
-
// type RoutesById = MyRoutesInfo['routesById']
|
|
155
|
-
// // ^?
|
|
156
|
-
// type RoutePaths = keyof RoutesById
|
|
157
|
-
// // ^?
|
|
158
|
-
// type InvoiceRoute = RoutesById['/dashboard/invoices/:invoiceId']
|
|
159
|
-
// // ^?
|
|
160
|
-
// type InvoiceLoaderData = InvoiceRoute['types']['AllLoaderData']
|
|
161
|
-
// // ^?
|
|
162
|
-
|
|
163
|
-
// //
|
|
164
|
-
// //
|
|
165
|
-
// //
|
|
166
|
-
// //
|
|
167
|
-
|
|
168
|
-
// //
|
|
169
|
-
// //
|
|
170
|
-
// //
|
|
171
|
-
// //
|
|
172
|
-
// //
|
|
173
|
-
// //
|
|
174
|
-
// //
|
|
175
|
-
// //
|
|
176
|
-
|
|
177
|
-
// //
|
|
178
|
-
// //
|
|
179
|
-
|
|
180
|
-
// //
|
|
181
|
-
// //
|
|
182
|
-
|
|
183
|
-
// // Build our routes. We could do this in our component, too.
|
|
184
|
-
// const routes = createRoutes().addChildren((createRoute) => [
|
|
185
|
-
// createRoute({ path: '/' }),
|
|
186
|
-
// createRoute({
|
|
187
|
-
// path: 'dashboard',
|
|
188
|
-
// loader: async () => {
|
|
189
|
-
// console.log('Fetching all invoices...')
|
|
190
|
-
// return {
|
|
191
|
-
// invoices: 'await fetchInvoices()',
|
|
192
|
-
// }
|
|
193
|
-
// },
|
|
194
|
-
// }).addChildren((createRoute) => [
|
|
195
|
-
// createRoute({ path: '/' }),
|
|
196
|
-
// createRoute({
|
|
197
|
-
// path: 'invoices',
|
|
198
|
-
// }).addChildren((createRoute) => [
|
|
199
|
-
// createRoute({
|
|
200
|
-
// path: '/',
|
|
201
|
-
// action: async (partialInvoice: { amount: number }, ctx) => {
|
|
202
|
-
// const invoice: { id: number; amount: number } = null!
|
|
203
|
-
// // // Redirect to the new invoice
|
|
204
|
-
// // ctx.router.navigate({
|
|
205
|
-
// // to: invoice.id,
|
|
206
|
-
// // // Use the current match for relative paths
|
|
207
|
-
// // from: ctx.match.pathname,
|
|
208
|
-
// // })
|
|
209
|
-
// return invoice
|
|
210
|
-
// },
|
|
211
|
-
// }),
|
|
212
|
-
// createRoute({
|
|
213
|
-
// path: ':invoiceId',
|
|
214
|
-
|
|
215
|
-
// loader: async ({ params: { invoiceId } }) => {
|
|
216
|
-
// console.log('Fetching invoice...')
|
|
217
|
-
// return {
|
|
218
|
-
// invoice: 'await fetchInvoiceById(invoiceId!)',
|
|
219
|
-
// }
|
|
220
|
-
// },
|
|
221
|
-
// // action: patchInvoice,
|
|
222
|
-
// }),
|
|
223
|
-
// ]),
|
|
224
|
-
// createRoute({
|
|
225
|
-
// path: 'users',
|
|
226
|
-
|
|
227
|
-
// loader: async () => {
|
|
228
|
-
// return {
|
|
229
|
-
// users: 'await fetchUsers()',
|
|
230
|
-
// }
|
|
231
|
-
// },
|
|
232
|
-
// searchSchema: {
|
|
233
|
-
// usersView: z
|
|
234
|
-
// .object({
|
|
235
|
-
// sortBy: z.enum(['name', 'id', 'email']).optional(),
|
|
236
|
-
// filterBy: z.string().optional(),
|
|
237
|
-
// })
|
|
238
|
-
// .optional(),
|
|
239
|
-
// },
|
|
240
|
-
// preSearchFilters: [
|
|
241
|
-
// // Keep the usersView search param around
|
|
242
|
-
// // while in this route (or it's children!)
|
|
243
|
-
// (search) => ({
|
|
244
|
-
// ...search,
|
|
245
|
-
// usersView: {
|
|
246
|
-
// ...search.usersView,
|
|
247
|
-
// },
|
|
248
|
-
// }),
|
|
249
|
-
// ],
|
|
250
|
-
// }).addChildren((createRoute) => [
|
|
251
|
-
// createRoute({
|
|
252
|
-
// path: ':userId',
|
|
253
|
-
|
|
254
|
-
// loader: async ({ params: { userId } }) => {
|
|
255
|
-
// return {
|
|
256
|
-
// user: 'await fetchUserById(userId!)',
|
|
257
|
-
// }
|
|
258
|
-
// },
|
|
259
|
-
// }),
|
|
260
|
-
// ]),
|
|
261
|
-
// ]),
|
|
262
|
-
// // Obviously, you can put routes in other files, too
|
|
263
|
-
// // reallyExpensiveRoute,
|
|
264
|
-
// createRoute({
|
|
265
|
-
// path: 'authenticated/', // Trailing slash doesn't mean anything
|
|
266
|
-
// }).addChildren((createRoute) => [
|
|
267
|
-
// createRoute({
|
|
268
|
-
// path: '/',
|
|
269
|
-
// }),
|
|
270
|
-
// ]),
|
|
271
|
-
// ])
|
|
272
|
-
|
|
273
|
-
// const router = new Router({
|
|
274
|
-
// routes,
|
|
275
|
-
// })
|
|
276
|
-
|
|
277
|
-
// const loaderData = router.getRoute('/dashboard/users/:userId').getLoaderData()
|
|
278
|
-
// // ^?
|
|
279
|
-
// const action = router.getRoute('/dashboard/invoices/').getAction()
|
|
280
|
-
// // ^?
|
|
281
|
-
// const result = action.submit({ amount: 10000 })
|
|
282
|
-
// // ^?
|
|
283
|
-
|
|
284
|
-
// const route = router.getRoute('/dashboard/invoices/')
|
|
285
|
-
|
|
286
|
-
// const linkProps = route.linkProps({
|
|
287
|
-
// // ^?
|
|
288
|
-
// to: '/dashboard/invoices/:invoiceId',
|
|
289
|
-
// params: {
|
|
290
|
-
// invoiceId: 2,
|
|
291
|
-
// },
|
|
292
|
-
// })
|
|
293
|
-
|
|
294
|
-
// const link = (
|
|
295
|
-
// <Link
|
|
296
|
-
// {...route.link({
|
|
297
|
-
// to: '/dashboard/invoices/:invoiceId',
|
|
298
|
-
// params: {
|
|
299
|
-
// invoiceId: 2,
|
|
300
|
-
// },
|
|
301
|
-
// })}
|
|
302
|
-
// />
|
|
303
|
-
// )
|
|
304
|
-
// // ^?
|
|
305
|
-
|
|
306
|
-
// ///
|
|
307
|
-
|
|
308
|
-
// //
|
|
309
|
-
|
|
310
|
-
// //
|