@tanstack/router-core 0.0.1-alpha.0 → 0.0.1-alpha.10
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/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +33 -0
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +1 -0
- package/build/cjs/node_modules/history/index.js +815 -0
- package/build/cjs/node_modules/history/index.js.map +1 -0
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +30 -0
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +1 -0
- package/build/cjs/packages/router-core/src/index.js +35 -1421
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/cjs/packages/router-core/src/path.js +222 -0
- package/build/cjs/packages/router-core/src/path.js.map +1 -0
- package/build/cjs/packages/router-core/src/qss.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +126 -0
- package/build/cjs/packages/router-core/src/route.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeConfig.js +69 -0
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeMatch.js +247 -0
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -0
- package/build/cjs/packages/router-core/src/router.js +809 -0
- package/build/cjs/packages/router-core/src/router.js.map +1 -0
- package/build/cjs/packages/router-core/src/searchParams.js +70 -0
- package/build/cjs/packages/router-core/src/searchParams.js.map +1 -0
- package/build/cjs/packages/router-core/src/utils.js +118 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -0
- package/build/esm/index.js +1350 -1231
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +388 -46
- package/build/types/index.d.ts +401 -343
- package/build/umd/index.development.js +1218 -1091
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
- package/src/frameworks.ts +13 -0
- package/src/index.ts +15 -2969
- package/src/link.ts +291 -0
- package/src/path.ts +236 -0
- package/src/qss.ts +1 -1
- package/src/route.ts +181 -0
- package/src/routeConfig.ts +523 -0
- package/src/routeInfo.ts +228 -0
- package/src/routeMatch.ts +340 -0
- package/src/router.ts +1211 -0
- package/src/searchParams.ts +54 -0
- package/src/utils.ts +157 -0
- package/build/cjs/packages/location-core/src/index.js +0 -1313
- package/build/cjs/packages/location-core/src/index.js.map +0 -1
- package/build/cjs/packages/location-core/src/qss.js +0 -70
- package/build/cjs/packages/location-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/createRoutes.js +0 -106
- package/build/cjs/packages/router-core/src/createRoutes.js.map +0 -1
- package/build/cjs/packages/router-core/src/createRoutes.test.js +0 -160
- package/build/cjs/packages/router-core/src/createRoutes.test.js.map +0 -1
- package/build/types/createRoutes.d.ts +0 -10
- package/build/types/createRoutes.test.d.ts +0 -1
- package/build/types/qss.d.ts +0 -2
- package/build/types/react-router/src/createRoutes.test.d.ts +0 -0
- package/build/types/react-router/src/index.d.ts +0 -59
- package/build/types/router-core/src/createRoutes.test.d.ts +0 -1
- package/build/types/router-core/src/index.d.ts +0 -504
- package/build/types/router-core/src/qss.d.ts +0 -2
- package/src/createRoutes.test.ts +0 -318
- package/src/package.json +0 -48
package/src/createRoutes.test.ts
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { Route } from '@tanstack/router-core'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
import {
|
|
4
|
-
createRouter,
|
|
5
|
-
AllRouteInfo,
|
|
6
|
-
createRouteConfig,
|
|
7
|
-
RelativeToPathAutoComplete,
|
|
8
|
-
} from '.'
|
|
9
|
-
|
|
10
|
-
// Build our routes. We could do this in our component, too.
|
|
11
|
-
const routeConfig = createRouteConfig().addChildren((createRoute) => [
|
|
12
|
-
createRoute({
|
|
13
|
-
path: '/',
|
|
14
|
-
validateSearch: (search) =>
|
|
15
|
-
z
|
|
16
|
-
.object({
|
|
17
|
-
version: z.number(),
|
|
18
|
-
})
|
|
19
|
-
.parse(search),
|
|
20
|
-
}),
|
|
21
|
-
createRoute({
|
|
22
|
-
path: '/test',
|
|
23
|
-
validateSearch: (search) =>
|
|
24
|
-
z
|
|
25
|
-
.object({
|
|
26
|
-
version: z.number(),
|
|
27
|
-
isGood: z.boolean(),
|
|
28
|
-
})
|
|
29
|
-
.parse(search),
|
|
30
|
-
}),
|
|
31
|
-
createRoute({
|
|
32
|
-
path: 'dashboard',
|
|
33
|
-
loader: async () => {
|
|
34
|
-
console.log('Fetching all invoices...')
|
|
35
|
-
return {
|
|
36
|
-
invoices: 'await fetchInvoices()',
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
}).addChildren((createRoute) => [
|
|
40
|
-
createRoute({ path: '/' }),
|
|
41
|
-
createRoute({
|
|
42
|
-
path: 'invoices',
|
|
43
|
-
}).addChildren((createRoute) => [
|
|
44
|
-
createRoute({
|
|
45
|
-
path: '/',
|
|
46
|
-
action: async (partialInvoice: { amount: number }) => {
|
|
47
|
-
const invoice: { id: number; amount: number } = null!
|
|
48
|
-
// // Redirect to the new invoice
|
|
49
|
-
// ctx.router.navigate({
|
|
50
|
-
// to: invoice.id,
|
|
51
|
-
// // Use the current match for relative paths
|
|
52
|
-
// from: ctx.match.pathname,
|
|
53
|
-
// })
|
|
54
|
-
return invoice
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
createRoute({
|
|
58
|
-
path: ':invoiceId',
|
|
59
|
-
parseParams: ({ invoiceId }) => ({ invoiceId: Number(invoiceId) }),
|
|
60
|
-
stringifyParams: ({ invoiceId }) => ({ invoiceId: String(invoiceId) }),
|
|
61
|
-
loader: async ({ params: { invoiceId } }) => {
|
|
62
|
-
console.log('Fetching invoice...')
|
|
63
|
-
return {
|
|
64
|
-
invoice: 'await fetchInvoiceById(invoiceId!)',
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
]),
|
|
69
|
-
createRoute({
|
|
70
|
-
path: 'users',
|
|
71
|
-
loader: async () => {
|
|
72
|
-
return {
|
|
73
|
-
users: 'await fetchUsers()',
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
validateSearch: (search) =>
|
|
77
|
-
z
|
|
78
|
-
.object({
|
|
79
|
-
usersView: z
|
|
80
|
-
.object({
|
|
81
|
-
sortBy: z.enum(['name', 'id', 'email']).optional(),
|
|
82
|
-
filterBy: z.string().optional(),
|
|
83
|
-
})
|
|
84
|
-
.optional(),
|
|
85
|
-
})
|
|
86
|
-
.parse(search),
|
|
87
|
-
preSearchFilters: [
|
|
88
|
-
// Keep the usersView search param around
|
|
89
|
-
// while in this route (or it's children!)
|
|
90
|
-
(search) => ({
|
|
91
|
-
...search,
|
|
92
|
-
usersView: {
|
|
93
|
-
...search.usersView,
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
],
|
|
97
|
-
}).addChildren((createRoute) => [
|
|
98
|
-
createRoute({
|
|
99
|
-
path: ':userId',
|
|
100
|
-
loader: async ({ params: { userId }, search }) => {
|
|
101
|
-
return {
|
|
102
|
-
user: 'await fetchUserById(userId!)',
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
action: async (partialUser: { amount: number }) => {
|
|
106
|
-
const invoice: { id: number; amount: number } = null!
|
|
107
|
-
// // Redirect to the new invoice
|
|
108
|
-
// ctx.router.navigate({
|
|
109
|
-
// to: invoice.id,
|
|
110
|
-
// // Use the current match for relative paths
|
|
111
|
-
// from: ctx.match.pathname,
|
|
112
|
-
// })
|
|
113
|
-
return invoice
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
]),
|
|
117
|
-
]),
|
|
118
|
-
// Obviously, you can put routes in other files, too
|
|
119
|
-
// reallyExpensiveRoute,
|
|
120
|
-
createRoute({
|
|
121
|
-
path: 'authenticated/', // Trailing slash doesn't mean anything
|
|
122
|
-
}).addChildren((createRoute) => [
|
|
123
|
-
createRoute({
|
|
124
|
-
path: '/',
|
|
125
|
-
}),
|
|
126
|
-
]),
|
|
127
|
-
])
|
|
128
|
-
|
|
129
|
-
type MyRoutesInfo = AllRouteInfo<typeof routeConfig>
|
|
130
|
-
// ^?
|
|
131
|
-
type RouteInfo = MyRoutesInfo['routeInfo']
|
|
132
|
-
type RoutesById = MyRoutesInfo['routeInfoById']
|
|
133
|
-
type RoutesTest = Route<MyRoutesInfo, MyRoutesInfo['routeInfoByFullPath']['/']>
|
|
134
|
-
// ^?
|
|
135
|
-
type RoutePaths = MyRoutesInfo['routeInfoByFullPath']
|
|
136
|
-
// ^?
|
|
137
|
-
type InvoiceRouteInfo = RoutesById['/dashboard/invoices/']
|
|
138
|
-
// ^?
|
|
139
|
-
type InvoiceLoaderData = InvoiceRouteInfo['loaderData']
|
|
140
|
-
// ^?//
|
|
141
|
-
type InvoiceAction = InvoiceRouteInfo['actionPayload']
|
|
142
|
-
// ^?
|
|
143
|
-
|
|
144
|
-
const router = createRouter({
|
|
145
|
-
routeConfig,
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const loaderData = router.getRoute('/dashboard/users/:userId')
|
|
149
|
-
// ^?
|
|
150
|
-
const route = router.getRoute('/dashboard/users/:userId')
|
|
151
|
-
// ^?
|
|
152
|
-
const action = route.action
|
|
153
|
-
// ^?
|
|
154
|
-
const result = action.submit({ amount: 10000 })
|
|
155
|
-
// ^?
|
|
156
|
-
|
|
157
|
-
router.buildLink({
|
|
158
|
-
to: '/dashboard/users/:userId',
|
|
159
|
-
params: {
|
|
160
|
-
userId: '2',
|
|
161
|
-
},
|
|
162
|
-
search: (prev) => ({
|
|
163
|
-
usersView: {
|
|
164
|
-
sortBy: 'email',
|
|
165
|
-
},
|
|
166
|
-
}),
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
// @ts-expect-error
|
|
170
|
-
router.buildLink({
|
|
171
|
-
from: '/',
|
|
172
|
-
to: '/test',
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
router.buildLink({
|
|
176
|
-
from: '/',
|
|
177
|
-
to: '/test',
|
|
178
|
-
search: () => {
|
|
179
|
-
return {
|
|
180
|
-
version: 2,
|
|
181
|
-
isGood: true,
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
router.buildLink({
|
|
187
|
-
from: '/test',
|
|
188
|
-
to: '/',
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
route.buildLink({
|
|
192
|
-
to: '',
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
router.getRoute('/dashboard').buildLink({
|
|
196
|
-
to: '/dashboard/invoices',
|
|
197
|
-
params: {
|
|
198
|
-
// @ts-expect-error
|
|
199
|
-
invoiceId: 2,
|
|
200
|
-
},
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
router.getRoute('/dashboard').buildLink({
|
|
204
|
-
to: '/dashboard/invoices/:invoiceId',
|
|
205
|
-
params: {
|
|
206
|
-
// @ts-expect-error
|
|
207
|
-
invoiceId: '2',
|
|
208
|
-
},
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
router.getRoute('/').buildLink({
|
|
212
|
-
to: '/dashboard/invoices/:invoiceId',
|
|
213
|
-
params: {
|
|
214
|
-
invoiceId: 2,
|
|
215
|
-
},
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
router.getRoute('/').buildLink({
|
|
219
|
-
to: '/',
|
|
220
|
-
search: {
|
|
221
|
-
version: 2,
|
|
222
|
-
},
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
router.getRoute('/').buildLink({
|
|
226
|
-
to: '/dashboard/users/:userId',
|
|
227
|
-
params: (current) => ({
|
|
228
|
-
userId:
|
|
229
|
-
// @ts-expect-error
|
|
230
|
-
current?.invoiceId,
|
|
231
|
-
}),
|
|
232
|
-
search: (old) => ({
|
|
233
|
-
usersView: {
|
|
234
|
-
sortBy: 'email' as const,
|
|
235
|
-
filterBy: String(old.version),
|
|
236
|
-
},
|
|
237
|
-
}),
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
router.getRoute('/dashboard/invoices/:invoiceId').buildLink({
|
|
241
|
-
to: '/dashboard/users/:userId',
|
|
242
|
-
params: (current) => ({
|
|
243
|
-
userId: `${current?.invoiceId}`,
|
|
244
|
-
}),
|
|
245
|
-
search: (prev) => {
|
|
246
|
-
return {
|
|
247
|
-
usersView: {
|
|
248
|
-
sortBy: 'name' as const,
|
|
249
|
-
filterBy: 'tanner',
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
router.getRoute('/dashboard/users/:userId').buildLink({
|
|
256
|
-
to: '/',
|
|
257
|
-
search: (prev) => {
|
|
258
|
-
return {
|
|
259
|
-
version: 2,
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
router.buildLink({
|
|
265
|
-
from: '/',
|
|
266
|
-
to: '/dashboard/users/:userId',
|
|
267
|
-
params: {
|
|
268
|
-
userId: '2',
|
|
269
|
-
},
|
|
270
|
-
search: (prev) => ({
|
|
271
|
-
usersView: {
|
|
272
|
-
sortBy: 'id',
|
|
273
|
-
filterBy: `${prev.version}`,
|
|
274
|
-
},
|
|
275
|
-
}),
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
router.getRoute('/').navigate({
|
|
279
|
-
// to: '.',
|
|
280
|
-
// TODO: What the heck? Why is any required here?
|
|
281
|
-
search: (prev: any) => ({
|
|
282
|
-
version: prev.version,
|
|
283
|
-
}),
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
router.buildLink({
|
|
287
|
-
from: '/dashboard/invoices',
|
|
288
|
-
to: '/dashboard',
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
router.getRoute('/').buildLink({
|
|
292
|
-
to: '/dashboard/invoices/:invoiceId',
|
|
293
|
-
params: {
|
|
294
|
-
invoiceId: 2,
|
|
295
|
-
},
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
router.getRoute('/dashboard/invoices/:invoiceId').buildLink({
|
|
299
|
-
to: '.',
|
|
300
|
-
params: (d) => ({
|
|
301
|
-
invoiceId: d.invoiceId,
|
|
302
|
-
}),
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
type test = RelativeToPathAutoComplete<
|
|
306
|
-
// ^?
|
|
307
|
-
MyRoutesInfo['fullPath'],
|
|
308
|
-
'/dashboard/invoices',
|
|
309
|
-
'..'
|
|
310
|
-
>
|
|
311
|
-
|
|
312
|
-
router.getRoute('/dashboard/invoices/:invoiceId').buildLink({
|
|
313
|
-
to: '../test',
|
|
314
|
-
search: {
|
|
315
|
-
version: 2,
|
|
316
|
-
isGood: true,
|
|
317
|
-
},
|
|
318
|
-
})
|
package/src/package.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tanstack/router-core",
|
|
3
|
-
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-alpha.0",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "tanstack/router",
|
|
7
|
-
"homepage": "https://tanstack.com/router",
|
|
8
|
-
"description": "",
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"registry": "https://registry.npmjs.org/"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"react",
|
|
14
|
-
"location",
|
|
15
|
-
"@tanstack/react-router",
|
|
16
|
-
"router",
|
|
17
|
-
"routing",
|
|
18
|
-
"async",
|
|
19
|
-
"async router",
|
|
20
|
-
"typescript"
|
|
21
|
-
],
|
|
22
|
-
"funding": {
|
|
23
|
-
"type": "github",
|
|
24
|
-
"url": "https://github.com/sponsors/tannerlinsley"
|
|
25
|
-
},
|
|
26
|
-
"module": "build/esm/index.js",
|
|
27
|
-
"main": "build/cjs/index.js",
|
|
28
|
-
"browser": "build/umd/index.production.js",
|
|
29
|
-
"types": "build/types/index.d.ts",
|
|
30
|
-
"engines": {
|
|
31
|
-
"node": ">=12"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"build/**",
|
|
35
|
-
"src"
|
|
36
|
-
],
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"react": ">=16",
|
|
39
|
-
"react-dom": ">=16"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@babel/runtime": "^7.16.7",
|
|
43
|
-
"history": "^5.2.0"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"babel-plugin-transform-async-to-promises": "^0.8.18"
|
|
47
|
-
}
|
|
48
|
-
}
|