@tanstack/router-core 0.0.1-beta.9 → 1.20.3-alpha.1
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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/Matches.cjs +13 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +109 -0
- package/dist/cjs/RouterProvider.d.cts +26 -0
- package/dist/cjs/defer.cjs +25 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/defer.d.cts +20 -0
- package/dist/cjs/fileRoute.d.cts +23 -0
- package/dist/cjs/history.d.cts +8 -0
- package/dist/cjs/index.cjs +80 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +41 -0
- package/dist/cjs/link.cjs +5 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +200 -0
- package/dist/cjs/location.d.cts +12 -0
- package/dist/cjs/manifest.d.cts +24 -0
- package/dist/cjs/not-found.cjs +13 -0
- package/dist/cjs/not-found.cjs.map +1 -0
- package/dist/cjs/not-found.d.cts +20 -0
- package/dist/cjs/path.cjs +412 -0
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +56 -0
- package/dist/cjs/qss.cjs +38 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/qss.d.cts +22 -0
- package/dist/cjs/redirect.cjs +34 -0
- package/dist/cjs/redirect.cjs.map +1 -0
- package/dist/cjs/redirect.d.cts +38 -0
- package/dist/cjs/root.cjs +5 -0
- package/dist/cjs/root.cjs.map +1 -0
- package/dist/cjs/root.d.cts +2 -0
- package/dist/cjs/route.cjs +119 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/route.d.cts +422 -0
- package/dist/cjs/routeInfo.d.cts +54 -0
- package/dist/cjs/router.cjs +1800 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/router.d.cts +630 -0
- package/dist/cjs/scroll-restoration.cjs +196 -0
- package/dist/cjs/scroll-restoration.cjs.map +1 -0
- package/dist/cjs/scroll-restoration.d.cts +38 -0
- package/dist/cjs/searchMiddleware.cjs +42 -0
- package/dist/cjs/searchMiddleware.cjs.map +1 -0
- package/dist/cjs/searchMiddleware.d.cts +5 -0
- package/dist/cjs/searchParams.cjs +61 -0
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/searchParams.d.cts +7 -0
- package/dist/cjs/serializer.d.cts +22 -0
- package/dist/cjs/structuralSharing.d.cts +4 -0
- package/dist/cjs/typePrimitives.d.cts +65 -0
- package/dist/cjs/useLoaderData.d.cts +5 -0
- package/dist/cjs/useLoaderDeps.d.cts +5 -0
- package/dist/cjs/useNavigate.d.cts +3 -0
- package/dist/cjs/useParams.d.cts +5 -0
- package/dist/cjs/useRouteContext.d.cts +9 -0
- package/dist/cjs/useSearch.d.cts +5 -0
- package/dist/cjs/utils.cjs +160 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +105 -0
- package/dist/cjs/validators.d.cts +51 -0
- package/dist/esm/Matches.d.ts +109 -0
- package/dist/esm/Matches.js +13 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +26 -0
- package/dist/esm/defer.d.ts +20 -0
- package/dist/esm/defer.js +25 -0
- package/dist/esm/defer.js.map +1 -0
- package/dist/esm/fileRoute.d.ts +23 -0
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +41 -0
- package/dist/esm/index.js +80 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/link.d.ts +200 -0
- package/dist/esm/link.js +5 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/location.d.ts +12 -0
- package/dist/esm/manifest.d.ts +24 -0
- package/dist/esm/not-found.d.ts +20 -0
- package/dist/esm/not-found.js +13 -0
- package/dist/esm/not-found.js.map +1 -0
- package/dist/esm/path.d.ts +56 -0
- package/dist/esm/path.js +412 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +22 -0
- package/dist/esm/qss.js +38 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/redirect.d.ts +38 -0
- package/dist/esm/redirect.js +34 -0
- package/dist/esm/redirect.js.map +1 -0
- package/dist/esm/root.d.ts +2 -0
- package/dist/esm/root.js +5 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/route.d.ts +422 -0
- package/dist/esm/route.js +119 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/routeInfo.d.ts +54 -0
- package/dist/esm/router.d.ts +630 -0
- package/dist/esm/router.js +1800 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/scroll-restoration.d.ts +38 -0
- package/dist/esm/scroll-restoration.js +196 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/searchMiddleware.d.ts +5 -0
- package/dist/esm/searchMiddleware.js +42 -0
- package/dist/esm/searchMiddleware.js.map +1 -0
- package/dist/esm/searchParams.d.ts +7 -0
- package/dist/esm/searchParams.js +61 -0
- package/dist/esm/searchParams.js.map +1 -0
- package/dist/esm/serializer.d.ts +22 -0
- package/dist/esm/structuralSharing.d.ts +4 -0
- package/dist/esm/typePrimitives.d.ts +65 -0
- package/dist/esm/useLoaderData.d.ts +5 -0
- package/dist/esm/useLoaderDeps.d.ts +5 -0
- package/dist/esm/useNavigate.d.ts +3 -0
- package/dist/esm/useParams.d.ts +5 -0
- package/dist/esm/useRouteContext.d.ts +9 -0
- package/dist/esm/useSearch.d.ts +5 -0
- package/dist/esm/utils.d.ts +105 -0
- package/dist/esm/utils.js +160 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validators.d.ts +51 -0
- package/package.json +36 -32
- package/src/Matches.ts +239 -0
- package/src/RouterProvider.ts +50 -0
- package/src/defer.ts +52 -0
- package/src/fileRoute.ts +140 -0
- package/src/history.ts +9 -0
- package/src/index.ts +421 -19
- package/src/link.ts +580 -286
- package/src/location.ts +13 -0
- package/src/manifest.ts +32 -0
- package/src/not-found.ts +29 -0
- package/src/path.ts +425 -49
- package/src/qss.ts +70 -41
- package/src/redirect.ts +100 -0
- package/src/root.ts +2 -0
- package/src/route.ts +1682 -218
- package/src/routeInfo.ts +224 -217
- package/src/router.ts +3100 -1073
- package/src/scroll-restoration.ts +340 -0
- package/src/searchMiddleware.ts +54 -0
- package/src/searchParams.ts +43 -20
- package/src/serializer.ts +32 -0
- package/src/structuralSharing.ts +7 -0
- package/src/typePrimitives.ts +181 -0
- package/src/useLoaderData.ts +20 -0
- package/src/useLoaderDeps.ts +13 -0
- package/src/useNavigate.ts +13 -0
- package/src/useParams.ts +20 -0
- package/src/useRouteContext.ts +39 -0
- package/src/useSearch.ts +20 -0
- package/src/utils.ts +369 -75
- package/src/validators.ts +121 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/index.js +0 -58
- package/build/cjs/packages/router-core/src/index.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js +0 -222
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js +0 -71
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -150
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -822
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js +0 -70
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -125
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
- package/build/esm/index.js +0 -2481
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4034
- package/build/stats-react.json +0 -493
- package/build/types/index.d.ts +0 -618
- package/build/umd/index.development.js +0 -2514
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -12
- package/build/umd/index.production.js.map +0 -1
- package/src/frameworks.ts +0 -12
- package/src/routeConfig.ts +0 -495
- package/src/routeMatch.ts +0 -374
package/package.json
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-core",
|
|
3
|
+
"version": "1.20.3-alpha.1",
|
|
4
|
+
"description": "Modern and scalable routing for React applications",
|
|
3
5
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.9",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"repository":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"registry": "https://registry.npmjs.org/"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/router.git",
|
|
10
|
+
"directory": "packages/router-core"
|
|
11
11
|
},
|
|
12
|
-
"
|
|
13
|
-
"react",
|
|
14
|
-
"location",
|
|
15
|
-
"router",
|
|
16
|
-
"routing",
|
|
17
|
-
"async",
|
|
18
|
-
"async router",
|
|
19
|
-
"typescript"
|
|
20
|
-
],
|
|
12
|
+
"homepage": "https://tanstack.com/router",
|
|
21
13
|
"funding": {
|
|
22
14
|
"type": "github",
|
|
23
15
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
24
16
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
17
|
+
"keywords": [
|
|
18
|
+
"history",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "dist/esm/index.d.ts",
|
|
23
|
+
"main": "dist/cjs/index.cjs",
|
|
24
|
+
"module": "dist/esm/index.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/esm/index.d.ts",
|
|
29
|
+
"default": "./dist/esm/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/cjs/index.d.cts",
|
|
33
|
+
"default": "./dist/cjs/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
31
37
|
},
|
|
38
|
+
"sideEffects": false,
|
|
32
39
|
"files": [
|
|
33
|
-
"
|
|
40
|
+
"dist",
|
|
34
41
|
"src"
|
|
35
42
|
],
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"react-dom": ">=16"
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=12"
|
|
39
45
|
},
|
|
40
46
|
"dependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"
|
|
47
|
+
"@tanstack/store": "^0.7.0",
|
|
48
|
+
"tiny-invariant": "^1.3.3",
|
|
49
|
+
"@tanstack/history": "1.20.3-alpha.1"
|
|
44
50
|
},
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
51
|
+
"scripts": {}
|
|
52
|
+
}
|
package/src/Matches.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import type { AnyRoute, StaticDataRouteOption } from './route'
|
|
2
|
+
import type {
|
|
3
|
+
AllContext,
|
|
4
|
+
AllLoaderData,
|
|
5
|
+
AllParams,
|
|
6
|
+
FullSearchSchema,
|
|
7
|
+
ParseRoute,
|
|
8
|
+
RouteById,
|
|
9
|
+
RouteIds,
|
|
10
|
+
} from './routeInfo'
|
|
11
|
+
import type { AnyRouter, RegisteredRouter } from './router'
|
|
12
|
+
import type { Constrain, ControlledPromise } from './utils'
|
|
13
|
+
|
|
14
|
+
export type AnyMatchAndValue = { match: any; value: any }
|
|
15
|
+
|
|
16
|
+
export type FindValueByIndex<
|
|
17
|
+
TKey,
|
|
18
|
+
TValue extends ReadonlyArray<any>,
|
|
19
|
+
> = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never
|
|
20
|
+
|
|
21
|
+
export type FindValueByKey<TKey, TValue> =
|
|
22
|
+
TValue extends ReadonlyArray<any>
|
|
23
|
+
? FindValueByIndex<TKey, TValue>
|
|
24
|
+
: TValue[TKey & keyof TValue]
|
|
25
|
+
|
|
26
|
+
export type CreateMatchAndValue<TMatch, TValue> = TValue extends any
|
|
27
|
+
? {
|
|
28
|
+
match: TMatch
|
|
29
|
+
value: TValue
|
|
30
|
+
}
|
|
31
|
+
: never
|
|
32
|
+
|
|
33
|
+
export type NextMatchAndValue<
|
|
34
|
+
TKey,
|
|
35
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
36
|
+
> = TMatchAndValue extends any
|
|
37
|
+
? CreateMatchAndValue<
|
|
38
|
+
TMatchAndValue['match'],
|
|
39
|
+
FindValueByKey<TKey, TMatchAndValue['value']>
|
|
40
|
+
>
|
|
41
|
+
: never
|
|
42
|
+
|
|
43
|
+
export type IsMatchKeyOf<TValue> =
|
|
44
|
+
TValue extends ReadonlyArray<any>
|
|
45
|
+
? number extends TValue['length']
|
|
46
|
+
? `${number}`
|
|
47
|
+
: keyof TValue & `${number}`
|
|
48
|
+
: TValue extends object
|
|
49
|
+
? keyof TValue & string
|
|
50
|
+
: never
|
|
51
|
+
|
|
52
|
+
export type IsMatchPath<
|
|
53
|
+
TParentPath extends string,
|
|
54
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
55
|
+
> = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`
|
|
56
|
+
|
|
57
|
+
export type IsMatchResult<
|
|
58
|
+
TKey,
|
|
59
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
60
|
+
> = TMatchAndValue extends any
|
|
61
|
+
? TKey extends keyof TMatchAndValue['value']
|
|
62
|
+
? TMatchAndValue['match']
|
|
63
|
+
: never
|
|
64
|
+
: never
|
|
65
|
+
|
|
66
|
+
export type IsMatchParse<
|
|
67
|
+
TPath,
|
|
68
|
+
TMatchAndValue extends AnyMatchAndValue,
|
|
69
|
+
TParentPath extends string = '',
|
|
70
|
+
> = TPath extends `${string}.${string}`
|
|
71
|
+
? TPath extends `${infer TFirst}.${infer TRest}`
|
|
72
|
+
? IsMatchParse<
|
|
73
|
+
TRest,
|
|
74
|
+
NextMatchAndValue<TFirst, TMatchAndValue>,
|
|
75
|
+
`${TParentPath}${TFirst}.`
|
|
76
|
+
>
|
|
77
|
+
: never
|
|
78
|
+
: {
|
|
79
|
+
path: IsMatchPath<TParentPath, TMatchAndValue>
|
|
80
|
+
result: IsMatchResult<TPath, TMatchAndValue>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type IsMatch<TMatch, TPath> = IsMatchParse<
|
|
84
|
+
TPath,
|
|
85
|
+
TMatch extends any ? { match: TMatch; value: TMatch } : never
|
|
86
|
+
>
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Narrows matches based on a path
|
|
90
|
+
* @experimental
|
|
91
|
+
*/
|
|
92
|
+
export const isMatch = <TMatch, TPath extends string>(
|
|
93
|
+
match: TMatch,
|
|
94
|
+
path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,
|
|
95
|
+
): match is IsMatch<TMatch, TPath>['result'] => {
|
|
96
|
+
const parts = (path as string).split('.')
|
|
97
|
+
let part
|
|
98
|
+
let value: any = match
|
|
99
|
+
|
|
100
|
+
while ((part = parts.shift()) != null && value != null) {
|
|
101
|
+
value = value[part]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return value != null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface DefaultRouteMatchExtensions {
|
|
108
|
+
scripts?: unknown
|
|
109
|
+
links?: unknown
|
|
110
|
+
headScripts?: unknown
|
|
111
|
+
meta?: unknown
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface RouteMatchExtensions extends DefaultRouteMatchExtensions {}
|
|
115
|
+
|
|
116
|
+
export interface RouteMatch<
|
|
117
|
+
out TRouteId,
|
|
118
|
+
out TFullPath,
|
|
119
|
+
out TAllParams,
|
|
120
|
+
out TFullSearchSchema,
|
|
121
|
+
out TLoaderData,
|
|
122
|
+
out TAllContext,
|
|
123
|
+
out TLoaderDeps,
|
|
124
|
+
> extends RouteMatchExtensions {
|
|
125
|
+
id: string
|
|
126
|
+
routeId: TRouteId
|
|
127
|
+
fullPath: TFullPath
|
|
128
|
+
index: number
|
|
129
|
+
pathname: string
|
|
130
|
+
params: TAllParams
|
|
131
|
+
_strictParams: TAllParams
|
|
132
|
+
status: 'pending' | 'success' | 'error' | 'redirected' | 'notFound'
|
|
133
|
+
isFetching: false | 'beforeLoad' | 'loader'
|
|
134
|
+
error: unknown
|
|
135
|
+
paramsError: unknown
|
|
136
|
+
searchError: unknown
|
|
137
|
+
updatedAt: number
|
|
138
|
+
loadPromise?: ControlledPromise<void>
|
|
139
|
+
beforeLoadPromise?: ControlledPromise<void>
|
|
140
|
+
loaderPromise?: ControlledPromise<void>
|
|
141
|
+
loaderData?: TLoaderData
|
|
142
|
+
__routeContext: Record<string, unknown>
|
|
143
|
+
__beforeLoadContext: Record<string, unknown>
|
|
144
|
+
context: TAllContext
|
|
145
|
+
search: TFullSearchSchema
|
|
146
|
+
_strictSearch: TFullSearchSchema
|
|
147
|
+
fetchCount: number
|
|
148
|
+
abortController: AbortController
|
|
149
|
+
cause: 'preload' | 'enter' | 'stay'
|
|
150
|
+
loaderDeps: TLoaderDeps
|
|
151
|
+
preload: boolean
|
|
152
|
+
invalid: boolean
|
|
153
|
+
headers?: Record<string, string>
|
|
154
|
+
globalNotFound?: boolean
|
|
155
|
+
staticData: StaticDataRouteOption
|
|
156
|
+
minPendingPromise?: ControlledPromise<void>
|
|
157
|
+
pendingTimeout?: ReturnType<typeof setTimeout>
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export type MakeRouteMatchFromRoute<TRoute extends AnyRoute> = RouteMatch<
|
|
161
|
+
TRoute['types']['id'],
|
|
162
|
+
TRoute['types']['fullPath'],
|
|
163
|
+
TRoute['types']['allParams'],
|
|
164
|
+
TRoute['types']['fullSearchSchema'],
|
|
165
|
+
TRoute['types']['loaderData'],
|
|
166
|
+
TRoute['types']['allContext'],
|
|
167
|
+
TRoute['types']['loaderDeps']
|
|
168
|
+
>
|
|
169
|
+
|
|
170
|
+
export type MakeRouteMatch<
|
|
171
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
172
|
+
TRouteId = RouteIds<TRouteTree>,
|
|
173
|
+
TStrict extends boolean = true,
|
|
174
|
+
> = RouteMatch<
|
|
175
|
+
TRouteId,
|
|
176
|
+
RouteById<TRouteTree, TRouteId>['types']['fullPath'],
|
|
177
|
+
TStrict extends false
|
|
178
|
+
? AllParams<TRouteTree>
|
|
179
|
+
: RouteById<TRouteTree, TRouteId>['types']['allParams'],
|
|
180
|
+
TStrict extends false
|
|
181
|
+
? FullSearchSchema<TRouteTree>
|
|
182
|
+
: RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema'],
|
|
183
|
+
TStrict extends false
|
|
184
|
+
? AllLoaderData<TRouteTree>
|
|
185
|
+
: RouteById<TRouteTree, TRouteId>['types']['loaderData'],
|
|
186
|
+
TStrict extends false
|
|
187
|
+
? AllContext<TRouteTree>
|
|
188
|
+
: RouteById<TRouteTree, TRouteId>['types']['allContext'],
|
|
189
|
+
RouteById<TRouteTree, TRouteId>['types']['loaderDeps']
|
|
190
|
+
>
|
|
191
|
+
|
|
192
|
+
export type AnyRouteMatch = RouteMatch<any, any, any, any, any, any, any>
|
|
193
|
+
|
|
194
|
+
export type MakeRouteMatchUnion<
|
|
195
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
196
|
+
TRoute extends AnyRoute = ParseRoute<TRouter['routeTree']>,
|
|
197
|
+
> = TRoute extends any
|
|
198
|
+
? RouteMatch<
|
|
199
|
+
TRoute['id'],
|
|
200
|
+
TRoute['fullPath'],
|
|
201
|
+
TRoute['types']['allParams'],
|
|
202
|
+
TRoute['types']['fullSearchSchema'],
|
|
203
|
+
TRoute['types']['loaderData'],
|
|
204
|
+
TRoute['types']['allContext'],
|
|
205
|
+
TRoute['types']['loaderDeps']
|
|
206
|
+
>
|
|
207
|
+
: never
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The `MatchRouteOptions` type is used to describe the options that can be used when matching a route.
|
|
211
|
+
*
|
|
212
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#matchrouteoptions-type)
|
|
213
|
+
*/
|
|
214
|
+
export interface MatchRouteOptions {
|
|
215
|
+
/**
|
|
216
|
+
* If `true`, will match against pending location instead of the current location.
|
|
217
|
+
*
|
|
218
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#pending-property)
|
|
219
|
+
*/
|
|
220
|
+
pending?: boolean
|
|
221
|
+
/**
|
|
222
|
+
* If `true`, will match against the current location with case sensitivity.
|
|
223
|
+
*
|
|
224
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#casesensitive-property)
|
|
225
|
+
*/
|
|
226
|
+
caseSensitive?: boolean
|
|
227
|
+
/**
|
|
228
|
+
* If `true`, will match against the current location's search params using a deep inclusive check. e.g. `{ a: 1 }` will match for a current location of `{ a: 1, b: 2 }`.
|
|
229
|
+
*
|
|
230
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#includesearch-property)
|
|
231
|
+
*/
|
|
232
|
+
includeSearch?: boolean
|
|
233
|
+
/**
|
|
234
|
+
* If `true`, will match against the current location using a fuzzy match. e.g. `/posts` will match for a current location of `/posts/123`.
|
|
235
|
+
*
|
|
236
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#fuzzy-property)
|
|
237
|
+
*/
|
|
238
|
+
fuzzy?: boolean
|
|
239
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { NavigateOptions, ToOptions } from './link'
|
|
2
|
+
import type { ParsedLocation } from './location'
|
|
3
|
+
import type { RoutePaths } from './routeInfo'
|
|
4
|
+
import type {
|
|
5
|
+
AnyRouter,
|
|
6
|
+
RegisteredRouter,
|
|
7
|
+
ViewTransitionOptions,
|
|
8
|
+
} from './router'
|
|
9
|
+
|
|
10
|
+
export interface MatchLocation {
|
|
11
|
+
to?: string | number | null
|
|
12
|
+
fuzzy?: boolean
|
|
13
|
+
caseSensitive?: boolean
|
|
14
|
+
from?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CommitLocationOptions {
|
|
18
|
+
replace?: boolean
|
|
19
|
+
resetScroll?: boolean
|
|
20
|
+
hashScrollIntoView?: boolean | ScrollIntoViewOptions
|
|
21
|
+
viewTransition?: boolean | ViewTransitionOptions
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated All navigations use React transitions under the hood now
|
|
24
|
+
**/
|
|
25
|
+
startTransition?: boolean
|
|
26
|
+
ignoreBlocker?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type NavigateFn = <
|
|
30
|
+
TRouter extends RegisteredRouter,
|
|
31
|
+
TTo extends string | undefined,
|
|
32
|
+
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
33
|
+
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
34
|
+
TMaskTo extends string = '',
|
|
35
|
+
>(
|
|
36
|
+
opts: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
37
|
+
) => Promise<void> | void
|
|
38
|
+
|
|
39
|
+
export type BuildLocationFn = <
|
|
40
|
+
TRouter extends AnyRouter,
|
|
41
|
+
TTo extends string | undefined,
|
|
42
|
+
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
43
|
+
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
44
|
+
TMaskTo extends string = '',
|
|
45
|
+
>(
|
|
46
|
+
opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
47
|
+
leaveParams?: boolean
|
|
48
|
+
_includeValidateSearch?: boolean
|
|
49
|
+
},
|
|
50
|
+
) => ParsedLocation
|
package/src/defer.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defaultSerializeError } from './router'
|
|
2
|
+
|
|
3
|
+
export const TSR_DEFERRED_PROMISE = Symbol.for('TSR_DEFERRED_PROMISE')
|
|
4
|
+
|
|
5
|
+
export type DeferredPromiseState<T> =
|
|
6
|
+
| {
|
|
7
|
+
status: 'pending'
|
|
8
|
+
data?: T
|
|
9
|
+
error?: unknown
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
status: 'success'
|
|
13
|
+
data: T
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
status: 'error'
|
|
17
|
+
data?: T
|
|
18
|
+
error: unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type DeferredPromise<T> = Promise<T> & {
|
|
22
|
+
[TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function defer<T>(
|
|
26
|
+
_promise: Promise<T>,
|
|
27
|
+
options?: {
|
|
28
|
+
serializeError?: typeof defaultSerializeError
|
|
29
|
+
},
|
|
30
|
+
) {
|
|
31
|
+
const promise = _promise as DeferredPromise<T>
|
|
32
|
+
// this is already deferred promise
|
|
33
|
+
if ((promise as any)[TSR_DEFERRED_PROMISE]) {
|
|
34
|
+
return promise
|
|
35
|
+
}
|
|
36
|
+
promise[TSR_DEFERRED_PROMISE] = { status: 'pending' }
|
|
37
|
+
|
|
38
|
+
promise
|
|
39
|
+
.then((data) => {
|
|
40
|
+
promise[TSR_DEFERRED_PROMISE].status = 'success'
|
|
41
|
+
promise[TSR_DEFERRED_PROMISE].data = data
|
|
42
|
+
})
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
promise[TSR_DEFERRED_PROMISE].status = 'error'
|
|
45
|
+
;(promise[TSR_DEFERRED_PROMISE] as any).error = {
|
|
46
|
+
data: (options?.serializeError ?? defaultSerializeError)(error),
|
|
47
|
+
__isServerError: true,
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return promise
|
|
52
|
+
}
|
package/src/fileRoute.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyContext,
|
|
3
|
+
AnyPathParams,
|
|
4
|
+
AnyRoute,
|
|
5
|
+
FileBaseRouteOptions,
|
|
6
|
+
ResolveParams,
|
|
7
|
+
Route,
|
|
8
|
+
RouteConstraints,
|
|
9
|
+
UpdatableRouteOptions,
|
|
10
|
+
} from './route'
|
|
11
|
+
import type { AnyValidator } from './validators'
|
|
12
|
+
|
|
13
|
+
export interface FileRouteTypes {
|
|
14
|
+
fileRoutesByFullPath: any
|
|
15
|
+
fullPaths: any
|
|
16
|
+
to: any
|
|
17
|
+
fileRoutesByTo: any
|
|
18
|
+
id: any
|
|
19
|
+
fileRoutesById: any
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type InferFileRouteTypes<TRouteTree extends AnyRoute> =
|
|
23
|
+
unknown extends TRouteTree['types']['fileRouteTypes']
|
|
24
|
+
? never
|
|
25
|
+
: TRouteTree['types']['fileRouteTypes'] extends FileRouteTypes
|
|
26
|
+
? TRouteTree['types']['fileRouteTypes']
|
|
27
|
+
: never
|
|
28
|
+
|
|
29
|
+
export interface FileRoutesByPath {
|
|
30
|
+
// '/': {
|
|
31
|
+
// parentRoute: typeof rootRoute
|
|
32
|
+
// }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface FileRouteOptions<
|
|
36
|
+
TFilePath extends string,
|
|
37
|
+
TParentRoute extends AnyRoute,
|
|
38
|
+
TId extends RouteConstraints['TId'],
|
|
39
|
+
TPath extends RouteConstraints['TPath'],
|
|
40
|
+
TFullPath extends RouteConstraints['TFullPath'],
|
|
41
|
+
TSearchValidator = undefined,
|
|
42
|
+
TParams = ResolveParams<TPath>,
|
|
43
|
+
TRouteContextFn = AnyContext,
|
|
44
|
+
TBeforeLoadFn = AnyContext,
|
|
45
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
46
|
+
TLoaderFn = undefined,
|
|
47
|
+
> extends FileBaseRouteOptions<
|
|
48
|
+
TParentRoute,
|
|
49
|
+
TId,
|
|
50
|
+
TPath,
|
|
51
|
+
TSearchValidator,
|
|
52
|
+
TParams,
|
|
53
|
+
TLoaderDeps,
|
|
54
|
+
TLoaderFn,
|
|
55
|
+
AnyContext,
|
|
56
|
+
TRouteContextFn,
|
|
57
|
+
TBeforeLoadFn
|
|
58
|
+
>,
|
|
59
|
+
UpdatableRouteOptions<
|
|
60
|
+
TParentRoute,
|
|
61
|
+
TId,
|
|
62
|
+
TFullPath,
|
|
63
|
+
TParams,
|
|
64
|
+
TSearchValidator,
|
|
65
|
+
TLoaderFn,
|
|
66
|
+
TLoaderDeps,
|
|
67
|
+
AnyContext,
|
|
68
|
+
TRouteContextFn,
|
|
69
|
+
TBeforeLoadFn
|
|
70
|
+
> {}
|
|
71
|
+
|
|
72
|
+
export type CreateFileRoute<
|
|
73
|
+
TFilePath extends string,
|
|
74
|
+
TParentRoute extends AnyRoute,
|
|
75
|
+
TId extends RouteConstraints['TId'],
|
|
76
|
+
TPath extends RouteConstraints['TPath'],
|
|
77
|
+
TFullPath extends RouteConstraints['TFullPath'],
|
|
78
|
+
> = <
|
|
79
|
+
TSearchValidator = undefined,
|
|
80
|
+
TParams = ResolveParams<TPath>,
|
|
81
|
+
TRouteContextFn = AnyContext,
|
|
82
|
+
TBeforeLoadFn = AnyContext,
|
|
83
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
84
|
+
TLoaderFn = undefined,
|
|
85
|
+
>(
|
|
86
|
+
options?: FileRouteOptions<
|
|
87
|
+
TFilePath,
|
|
88
|
+
TParentRoute,
|
|
89
|
+
TId,
|
|
90
|
+
TPath,
|
|
91
|
+
TFullPath,
|
|
92
|
+
TSearchValidator,
|
|
93
|
+
TParams,
|
|
94
|
+
TRouteContextFn,
|
|
95
|
+
TBeforeLoadFn,
|
|
96
|
+
TLoaderDeps,
|
|
97
|
+
TLoaderFn
|
|
98
|
+
>,
|
|
99
|
+
) => Route<
|
|
100
|
+
TParentRoute,
|
|
101
|
+
TPath,
|
|
102
|
+
TFullPath,
|
|
103
|
+
TFilePath,
|
|
104
|
+
TId,
|
|
105
|
+
TSearchValidator,
|
|
106
|
+
TParams,
|
|
107
|
+
AnyContext,
|
|
108
|
+
TRouteContextFn,
|
|
109
|
+
TBeforeLoadFn,
|
|
110
|
+
TLoaderDeps,
|
|
111
|
+
TLoaderFn,
|
|
112
|
+
unknown,
|
|
113
|
+
unknown
|
|
114
|
+
>
|
|
115
|
+
|
|
116
|
+
export type LazyRouteOptions = Pick<
|
|
117
|
+
UpdatableRouteOptions<
|
|
118
|
+
AnyRoute,
|
|
119
|
+
string,
|
|
120
|
+
string,
|
|
121
|
+
AnyPathParams,
|
|
122
|
+
AnyValidator,
|
|
123
|
+
{},
|
|
124
|
+
AnyContext,
|
|
125
|
+
AnyContext,
|
|
126
|
+
AnyContext,
|
|
127
|
+
AnyContext
|
|
128
|
+
>,
|
|
129
|
+
'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'
|
|
130
|
+
>
|
|
131
|
+
|
|
132
|
+
export interface LazyRoute<in out TRoute extends AnyRoute> {
|
|
133
|
+
options: {
|
|
134
|
+
id: string
|
|
135
|
+
} & LazyRouteOptions
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type CreateLazyFileRoute<TRoute extends AnyRoute> = (
|
|
139
|
+
opts: LazyRouteOptions,
|
|
140
|
+
) => LazyRoute<TRoute>
|
package/src/history.ts
ADDED