@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.200
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/build/cjs/defer.js +39 -0
- package/build/cjs/defer.js.map +1 -0
- package/build/cjs/fileRoute.js +29 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +89 -0
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +45 -56
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -15
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +114 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +1277 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/scroll-restoration.js +139 -0
- package/build/cjs/scroll-restoration.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +32 -19
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/utils.js +132 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1565 -2106
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +219 -241
- package/build/types/defer.d.ts +19 -0
- package/build/types/fileRoute.d.ts +35 -0
- package/build/types/index.d.ts +13 -611
- package/build/types/link.d.ts +96 -0
- package/build/types/path.d.ts +16 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/route.d.ts +261 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +265 -0
- package/build/types/scroll-restoration.d.ts +6 -0
- package/build/types/searchParams.d.ts +5 -0
- package/build/types/utils.d.ts +51 -0
- package/build/umd/index.development.js +1917 -2070
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +23 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +13 -7
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +156 -0
- package/src/index.ts +5 -11
- package/src/link.ts +149 -123
- package/src/path.ts +37 -17
- package/src/qss.ts +1 -1
- package/src/route.ts +861 -231
- package/src/routeInfo.ts +47 -205
- package/src/router.ts +1818 -952
- package/src/scroll-restoration.ts +179 -0
- package/src/searchParams.ts +31 -9
- package/src/utils.ts +106 -43
- 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/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -161
- 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 -789
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -118
- package/build/cjs/packages/router-core/src/utils.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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.200",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
24
24
|
},
|
|
25
25
|
"module": "build/esm/index.js",
|
|
26
|
-
"main": "build/cjs/
|
|
26
|
+
"main": "build/cjs/index.js",
|
|
27
27
|
"browser": "build/umd/index.production.js",
|
|
28
28
|
"types": "build/types/index.d.ts",
|
|
29
29
|
"engines": {
|
|
@@ -33,16 +33,22 @@
|
|
|
33
33
|
"build/**",
|
|
34
34
|
"src"
|
|
35
35
|
],
|
|
36
|
+
"sideEffects": false,
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"react": ">=16",
|
|
38
39
|
"react-dom": ">=16"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@babel/runtime": "^7.16.7",
|
|
42
|
-
"
|
|
43
|
-
"tiny-
|
|
43
|
+
"tiny-invariant": "^1.3.1",
|
|
44
|
+
"tiny-warning": "^1.0.3",
|
|
45
|
+
"@tanstack/store": "^0.0.1",
|
|
46
|
+
"@gisatcz/cross-package-react-context": "^0.2.0",
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.200"
|
|
44
48
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "rollup --config rollup.config.js",
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"test:dev": "vitest --watch"
|
|
47
53
|
}
|
|
48
|
-
}
|
|
54
|
+
}
|
package/src/defer.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type DeferredPromiseState<T> = { uid: string } & (
|
|
2
|
+
| {
|
|
3
|
+
status: 'pending'
|
|
4
|
+
data?: T
|
|
5
|
+
error?: unknown
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
status: 'success'
|
|
9
|
+
data: T
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
status: 'error'
|
|
13
|
+
data?: T
|
|
14
|
+
error: unknown
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export type DeferredPromise<T> = Promise<T> & {
|
|
19
|
+
__deferredState: DeferredPromiseState<T>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function defer<T>(_promise: Promise<T>) {
|
|
23
|
+
const promise = _promise as DeferredPromise<T>
|
|
24
|
+
|
|
25
|
+
if (!promise.__deferredState) {
|
|
26
|
+
promise.__deferredState = {
|
|
27
|
+
uid: Math.random().toString(36).slice(2),
|
|
28
|
+
status: 'pending',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const state = promise.__deferredState
|
|
32
|
+
|
|
33
|
+
promise
|
|
34
|
+
.then((data) => {
|
|
35
|
+
state.status = 'success' as any
|
|
36
|
+
state.data = data
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
state.status = 'error' as any
|
|
40
|
+
state.error = error
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return promise
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isDehydratedDeferred(obj: any): boolean {
|
|
48
|
+
return (
|
|
49
|
+
typeof obj === 'object' &&
|
|
50
|
+
obj !== null &&
|
|
51
|
+
!(obj instanceof Promise) &&
|
|
52
|
+
!obj.then &&
|
|
53
|
+
'__deferredState' in obj
|
|
54
|
+
)
|
|
55
|
+
}
|
package/src/fileRoute.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ParsePathParams } from './link'
|
|
2
|
+
import {
|
|
3
|
+
AnyRoute,
|
|
4
|
+
ResolveFullPath,
|
|
5
|
+
ResolveFullSearchSchema,
|
|
6
|
+
MergeFromFromParent,
|
|
7
|
+
RouteContext,
|
|
8
|
+
AnyContext,
|
|
9
|
+
RouteOptions,
|
|
10
|
+
InferFullSearchSchema,
|
|
11
|
+
UpdatableRouteOptions,
|
|
12
|
+
Route,
|
|
13
|
+
AnyPathParams,
|
|
14
|
+
RootRouteId,
|
|
15
|
+
TrimPathLeft,
|
|
16
|
+
RouteConstraints,
|
|
17
|
+
} from './route'
|
|
18
|
+
import { DeepMergeAll, Expand, IsAny } from './utils'
|
|
19
|
+
|
|
20
|
+
export interface FileRoutesByPath {
|
|
21
|
+
// '/': {
|
|
22
|
+
// parentRoute: typeof rootRoute
|
|
23
|
+
// }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Replace<
|
|
27
|
+
S extends string,
|
|
28
|
+
From extends string,
|
|
29
|
+
To extends string,
|
|
30
|
+
> = S extends `${infer Start}${From}${infer Rest}`
|
|
31
|
+
? `${Start}${To}${Replace<Rest, From, To>}`
|
|
32
|
+
: S
|
|
33
|
+
|
|
34
|
+
export type TrimLeft<
|
|
35
|
+
T extends string,
|
|
36
|
+
S extends string,
|
|
37
|
+
> = T extends `${S}${infer U}` ? U : T
|
|
38
|
+
|
|
39
|
+
export type TrimRight<
|
|
40
|
+
T extends string,
|
|
41
|
+
S extends string,
|
|
42
|
+
> = T extends `${infer U}${S}` ? U : T
|
|
43
|
+
|
|
44
|
+
export type Trim<T extends string, S extends string> = TrimLeft<
|
|
45
|
+
TrimRight<T, S>,
|
|
46
|
+
S
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
export type RemoveUnderScores<T extends string> = Replace<
|
|
50
|
+
Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>,
|
|
51
|
+
'/_',
|
|
52
|
+
'/'
|
|
53
|
+
>
|
|
54
|
+
|
|
55
|
+
export type ResolveFilePath<
|
|
56
|
+
TParentRoute extends AnyRoute,
|
|
57
|
+
TFilePath extends string,
|
|
58
|
+
> = TParentRoute['id'] extends RootRouteId
|
|
59
|
+
? TrimPathLeft<TFilePath>
|
|
60
|
+
: Replace<
|
|
61
|
+
TrimPathLeft<TFilePath>,
|
|
62
|
+
TrimPathLeft<TParentRoute['types']['customId']>,
|
|
63
|
+
''
|
|
64
|
+
>
|
|
65
|
+
|
|
66
|
+
export type FileRoutePath<
|
|
67
|
+
TParentRoute extends AnyRoute,
|
|
68
|
+
TFilePath extends string,
|
|
69
|
+
> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`
|
|
70
|
+
? string
|
|
71
|
+
: ResolveFilePath<TParentRoute, TFilePath>
|
|
72
|
+
|
|
73
|
+
export class FileRoute<
|
|
74
|
+
TFilePath extends keyof FileRoutesByPath,
|
|
75
|
+
TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
|
|
76
|
+
TId extends RouteConstraints['TId'] = TFilePath,
|
|
77
|
+
TPath extends RouteConstraints['TPath'] = FileRoutePath<
|
|
78
|
+
TParentRoute,
|
|
79
|
+
TFilePath
|
|
80
|
+
>,
|
|
81
|
+
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
82
|
+
TParentRoute,
|
|
83
|
+
RemoveUnderScores<TPath>
|
|
84
|
+
>,
|
|
85
|
+
> {
|
|
86
|
+
constructor(public path: TFilePath) {}
|
|
87
|
+
|
|
88
|
+
createRoute = <
|
|
89
|
+
TLoaderContext extends RouteConstraints['TLoaderContext'] = {},
|
|
90
|
+
TLoader = unknown,
|
|
91
|
+
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
92
|
+
TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
93
|
+
TParentRoute,
|
|
94
|
+
TSearchSchema
|
|
95
|
+
>,
|
|
96
|
+
TParams extends RouteConstraints['TParams'] = ParsePathParams<TPath> extends never
|
|
97
|
+
? AnyPathParams
|
|
98
|
+
: Record<ParsePathParams<TPath>, RouteConstraints['TPath']>,
|
|
99
|
+
TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<
|
|
100
|
+
TParentRoute['types']['allParams'],
|
|
101
|
+
TParams
|
|
102
|
+
>,
|
|
103
|
+
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
104
|
+
TContext extends RouteConstraints['TAllContext'] = Expand<
|
|
105
|
+
DeepMergeAll<
|
|
106
|
+
[
|
|
107
|
+
IsAny<TParentRoute['types']['context'], {}>,
|
|
108
|
+
TLoaderContext,
|
|
109
|
+
TRouteContext,
|
|
110
|
+
]
|
|
111
|
+
>
|
|
112
|
+
>,
|
|
113
|
+
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
114
|
+
TChildren extends RouteConstraints['TChildren'] = unknown,
|
|
115
|
+
TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
|
|
116
|
+
>(
|
|
117
|
+
options: Omit<
|
|
118
|
+
RouteOptions<
|
|
119
|
+
TParentRoute,
|
|
120
|
+
string,
|
|
121
|
+
string,
|
|
122
|
+
TLoaderContext,
|
|
123
|
+
TLoader,
|
|
124
|
+
TSearchSchema,
|
|
125
|
+
TFullSearchSchema,
|
|
126
|
+
TParams,
|
|
127
|
+
TAllParams,
|
|
128
|
+
TRouteContext,
|
|
129
|
+
TContext
|
|
130
|
+
>,
|
|
131
|
+
'getParentRoute' | 'path' | 'id'
|
|
132
|
+
> &
|
|
133
|
+
UpdatableRouteOptions<TLoader, TFullSearchSchema, TAllParams, TContext>,
|
|
134
|
+
): Route<
|
|
135
|
+
TParentRoute,
|
|
136
|
+
TPath,
|
|
137
|
+
TFullPath,
|
|
138
|
+
TFilePath,
|
|
139
|
+
TId,
|
|
140
|
+
TLoaderContext,
|
|
141
|
+
TLoader,
|
|
142
|
+
TSearchSchema,
|
|
143
|
+
TFullSearchSchema,
|
|
144
|
+
TParams,
|
|
145
|
+
TAllParams,
|
|
146
|
+
TRouteContext,
|
|
147
|
+
TContext,
|
|
148
|
+
TRouterContext,
|
|
149
|
+
TChildren,
|
|
150
|
+
TRouteTree
|
|
151
|
+
> => {
|
|
152
|
+
const route = new Route(options as any)
|
|
153
|
+
;(route as any).isRoot = false
|
|
154
|
+
return route as any
|
|
155
|
+
}
|
|
156
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
createHashHistory,
|
|
3
|
-
createBrowserHistory,
|
|
4
|
-
createMemoryHistory,
|
|
5
|
-
} from 'history'
|
|
6
|
-
|
|
1
|
+
export * from '@tanstack/history'
|
|
7
2
|
export { default as invariant } from 'tiny-invariant'
|
|
8
|
-
|
|
9
|
-
export * from './frameworks'
|
|
10
|
-
export * from './index'
|
|
3
|
+
export { default as warning } from 'tiny-warning'
|
|
11
4
|
export * from './link'
|
|
12
5
|
export * from './path'
|
|
13
6
|
export * from './qss'
|
|
14
7
|
export * from './route'
|
|
15
|
-
export * from './
|
|
8
|
+
export * from './fileRoute'
|
|
16
9
|
export * from './routeInfo'
|
|
17
|
-
export * from './routeMatch'
|
|
18
10
|
export * from './router'
|
|
19
11
|
export * from './searchParams'
|
|
20
12
|
export * from './utils'
|
|
13
|
+
export * from './scroll-restoration'
|
|
14
|
+
export * from './defer'
|
package/src/link.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Trim } from './fileRoute'
|
|
2
|
+
import { AnyRoute } from './route'
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
AllParams,
|
|
5
|
+
FullSearchSchema,
|
|
6
|
+
RouteByPath,
|
|
7
|
+
RouteIds,
|
|
8
|
+
RoutePaths,
|
|
6
9
|
} from './routeInfo'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
10
|
+
import { LocationState, ParsedLocation, RegisteredRouter } from './router'
|
|
11
|
+
import {
|
|
12
|
+
Expand,
|
|
13
|
+
NoInfer,
|
|
14
|
+
NonNullableUpdater,
|
|
15
|
+
PickRequired,
|
|
16
|
+
UnionToIntersection,
|
|
17
|
+
Updater,
|
|
18
|
+
} from './utils'
|
|
9
19
|
|
|
10
20
|
export type LinkInfo =
|
|
11
21
|
| {
|
|
@@ -14,20 +24,17 @@ export type LinkInfo =
|
|
|
14
24
|
}
|
|
15
25
|
| {
|
|
16
26
|
type: 'internal'
|
|
17
|
-
next:
|
|
27
|
+
next: ParsedLocation
|
|
18
28
|
handleFocus: (e: any) => void
|
|
19
29
|
handleClick: (e: any) => void
|
|
20
30
|
handleEnter: (e: any) => void
|
|
21
31
|
handleLeave: (e: any) => void
|
|
32
|
+
handleTouchStart: (e: any) => void
|
|
22
33
|
isActive: boolean
|
|
23
34
|
disabled?: boolean
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
type
|
|
27
|
-
? true
|
|
28
|
-
: false
|
|
29
|
-
|
|
30
|
-
type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
|
|
37
|
+
export type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
|
|
31
38
|
? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>
|
|
32
39
|
: T extends `${infer L}//`
|
|
33
40
|
? `${CleanPath<L>}/`
|
|
@@ -57,20 +64,20 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
|
|
|
57
64
|
: never
|
|
58
65
|
: never
|
|
59
66
|
|
|
60
|
-
export type ParsePathParams<T extends string> =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
: never
|
|
64
|
-
: never
|
|
67
|
+
export type ParsePathParams<T extends string> = keyof {
|
|
68
|
+
[K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K
|
|
69
|
+
}
|
|
65
70
|
|
|
66
|
-
type Join<T> = T extends []
|
|
71
|
+
export type Join<T, Delimiter extends string = '/'> = T extends []
|
|
67
72
|
? ''
|
|
68
73
|
: T extends [infer L extends string]
|
|
69
74
|
? L
|
|
70
75
|
: T extends [infer L extends string, ...infer Tail extends [...string[]]]
|
|
71
|
-
? CleanPath<`${L}
|
|
76
|
+
? CleanPath<`${L}${Delimiter}${Join<Tail>}`>
|
|
72
77
|
: never
|
|
73
78
|
|
|
79
|
+
export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never
|
|
80
|
+
|
|
74
81
|
export type RelativeToPathAutoComplete<
|
|
75
82
|
AllPaths extends string,
|
|
76
83
|
TFrom extends string,
|
|
@@ -106,126 +113,164 @@ export type RelativeToPathAutoComplete<
|
|
|
106
113
|
]
|
|
107
114
|
? `${TTo}${Join<RestPath>}`
|
|
108
115
|
: never
|
|
109
|
-
:
|
|
116
|
+
:
|
|
117
|
+
| (TFrom extends `/`
|
|
118
|
+
? never
|
|
119
|
+
: SplitPaths extends [...Split<TFrom, false>, ...infer RestPath]
|
|
120
|
+
? Join<RestPath> extends { length: 0 }
|
|
121
|
+
? never
|
|
122
|
+
: './'
|
|
123
|
+
: never)
|
|
124
|
+
| (TFrom extends `/` ? never : '../')
|
|
125
|
+
| AllPaths
|
|
110
126
|
|
|
111
|
-
export type
|
|
112
|
-
|
|
113
|
-
TFrom extends
|
|
114
|
-
TTo extends string = '
|
|
115
|
-
> =
|
|
116
|
-
|
|
127
|
+
export type NavigateOptions<
|
|
128
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
129
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
130
|
+
TTo extends string = '',
|
|
131
|
+
TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
|
|
132
|
+
TMaskTo extends string = '',
|
|
133
|
+
> = ToOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
134
|
+
// `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
|
|
117
135
|
replace?: boolean
|
|
136
|
+
resetScroll?: boolean
|
|
118
137
|
}
|
|
119
138
|
|
|
120
139
|
export type ToOptions<
|
|
121
|
-
|
|
122
|
-
TFrom extends
|
|
123
|
-
TTo extends string = '
|
|
124
|
-
|
|
140
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
141
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
142
|
+
TTo extends string = '',
|
|
143
|
+
TMaskFrom extends RoutePaths<TRouteTree> = '/',
|
|
144
|
+
TMaskTo extends string = '',
|
|
145
|
+
> = ToSubOptions<TRouteTree, TFrom, TTo> & {
|
|
146
|
+
mask?: ToMaskOptions<TRouteTree, TMaskFrom, TMaskTo>
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type ToMaskOptions<
|
|
150
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
151
|
+
TMaskFrom extends RoutePaths<TRouteTree> = '/',
|
|
152
|
+
TMaskTo extends string = '',
|
|
153
|
+
> = ToSubOptions<TRouteTree, TMaskFrom, TMaskTo> & {
|
|
154
|
+
unmaskOnReload?: boolean
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type ToSubOptions<
|
|
158
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
159
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
160
|
+
TTo extends string = '',
|
|
161
|
+
TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,
|
|
125
162
|
> = {
|
|
126
|
-
to?: ToPathOption<
|
|
163
|
+
to?: ToPathOption<TRouteTree, TFrom, TTo>
|
|
127
164
|
// The new has string or a function to update it
|
|
128
|
-
hash?: Updater<string>
|
|
165
|
+
hash?: true | Updater<string>
|
|
166
|
+
// State to pass to the history stack
|
|
167
|
+
state?: true | NonNullableUpdater<LocationState>
|
|
129
168
|
// The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required
|
|
130
169
|
from?: TFrom
|
|
131
170
|
// // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
|
|
132
171
|
// fromCurrent?: boolean
|
|
133
|
-
} & CheckPath<
|
|
134
|
-
SearchParamOptions<
|
|
135
|
-
PathParamOptions<
|
|
172
|
+
} & CheckPath<TRouteTree, NoInfer<TResolved>, {}> &
|
|
173
|
+
SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> &
|
|
174
|
+
PathParamOptions<TRouteTree, TFrom, TResolved>
|
|
136
175
|
|
|
137
|
-
type SearchParamOptions<
|
|
138
|
-
|
|
176
|
+
export type SearchParamOptions<
|
|
177
|
+
TRouteTree extends AnyRoute,
|
|
139
178
|
TFrom,
|
|
140
179
|
TTo,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
180
|
+
TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,
|
|
181
|
+
TFromSearchEnsured = '/' extends TFrom
|
|
182
|
+
? FullSearchSchema<TRouteTree>
|
|
183
|
+
: Expand<
|
|
184
|
+
UnionToIntersection<
|
|
185
|
+
PickRequired<
|
|
186
|
+
RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']
|
|
187
|
+
>
|
|
188
|
+
>
|
|
189
|
+
>,
|
|
190
|
+
TFromSearchOptional = Omit<AllParams<TRouteTree>, keyof TFromSearchEnsured>,
|
|
191
|
+
TFromSearch = Expand<TFromSearchEnsured & TFromSearchOptional>,
|
|
192
|
+
TToSearch = '' extends TTo
|
|
193
|
+
? FullSearchSchema<TRouteTree>
|
|
194
|
+
: Expand<RouteByPath<TRouteTree, TResolved>['types']['fullSearchSchema']>,
|
|
195
|
+
> = keyof PickRequired<TToSearch> extends never
|
|
149
196
|
? {
|
|
150
|
-
search?: SearchReducer<
|
|
197
|
+
search?: true | SearchReducer<TFromSearch, TToSearch>
|
|
151
198
|
}
|
|
152
199
|
: {
|
|
153
|
-
|
|
154
|
-
|
|
200
|
+
search: TFromSearchEnsured extends PickRequired<TToSearch>
|
|
201
|
+
? true | SearchReducer<TFromSearch, TToSearch>
|
|
202
|
+
: SearchReducer<TFromSearch, TToSearch>
|
|
155
203
|
}
|
|
156
204
|
|
|
157
|
-
type SearchReducer<TFrom, TTo> =
|
|
158
|
-
| { [TKey in keyof TTo]: TTo[TKey] }
|
|
159
|
-
| ((current: TFrom) => TTo)
|
|
205
|
+
type SearchReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
|
|
160
206
|
|
|
161
|
-
type PathParamOptions<
|
|
162
|
-
|
|
207
|
+
export type PathParamOptions<
|
|
208
|
+
TRouteTree extends AnyRoute,
|
|
163
209
|
TFrom,
|
|
164
210
|
TTo,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
211
|
+
TFromParamsEnsured = Expand<
|
|
212
|
+
UnionToIntersection<
|
|
213
|
+
PickRequired<RouteByPath<TRouteTree, TFrom>['types']['allParams']>
|
|
214
|
+
>
|
|
215
|
+
>,
|
|
216
|
+
TFromParamsOptional = Omit<AllParams<TRouteTree>, keyof TFromParamsEnsured>,
|
|
217
|
+
TFromParams = Expand<TFromParamsOptional & TFromParamsEnsured>,
|
|
218
|
+
TToParams = Expand<RouteByPath<TRouteTree, TTo>['types']['allParams']>,
|
|
219
|
+
> = keyof PickRequired<TToParams> extends never
|
|
220
|
+
? {
|
|
221
|
+
params?: true | ParamsReducer<TFromParams, TToParams>
|
|
222
|
+
}
|
|
223
|
+
: {
|
|
224
|
+
params: TFromParamsEnsured extends PickRequired<TToParams>
|
|
225
|
+
? true | ParamsReducer<TFromParams, TToParams>
|
|
226
|
+
: ParamsReducer<TFromParams, TToParams>
|
|
227
|
+
}
|
|
182
228
|
|
|
183
229
|
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
|
|
184
230
|
|
|
185
231
|
export type ToPathOption<
|
|
186
|
-
|
|
187
|
-
TFrom extends
|
|
188
|
-
TTo extends string = '
|
|
232
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
233
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
234
|
+
TTo extends string = '',
|
|
189
235
|
> =
|
|
190
236
|
| TTo
|
|
191
237
|
| RelativeToPathAutoComplete<
|
|
192
|
-
|
|
238
|
+
RoutePaths<TRouteTree>,
|
|
193
239
|
NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
|
|
194
240
|
NoInfer<TTo> & string
|
|
195
241
|
>
|
|
196
242
|
|
|
197
243
|
export type ToIdOption<
|
|
198
|
-
|
|
199
|
-
TFrom extends
|
|
200
|
-
TTo extends string = '
|
|
244
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
245
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
246
|
+
TTo extends string = '',
|
|
201
247
|
> =
|
|
202
248
|
| TTo
|
|
203
249
|
| RelativeToPathAutoComplete<
|
|
204
|
-
|
|
250
|
+
RouteIds<TRouteTree>,
|
|
205
251
|
NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',
|
|
206
252
|
NoInfer<TTo> & string
|
|
207
253
|
>
|
|
208
254
|
|
|
209
|
-
interface ActiveOptions {
|
|
255
|
+
export interface ActiveOptions {
|
|
210
256
|
exact?: boolean
|
|
211
257
|
includeHash?: boolean
|
|
258
|
+
includeSearch?: boolean
|
|
212
259
|
}
|
|
213
260
|
|
|
214
261
|
export type LinkOptions<
|
|
215
|
-
|
|
216
|
-
TFrom extends
|
|
217
|
-
TTo extends string = '
|
|
218
|
-
> =
|
|
262
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
263
|
+
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
264
|
+
TTo extends string = '',
|
|
265
|
+
TMaskFrom extends RoutePaths<TRouteTree> = TFrom,
|
|
266
|
+
TMaskTo extends string = '',
|
|
267
|
+
> = NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
219
268
|
// The standard anchor tag target attribute
|
|
220
269
|
target?: HTMLAnchorElement['target']
|
|
221
270
|
// Defaults to `{ exact: false, includeHash: false }`
|
|
222
271
|
activeOptions?: ActiveOptions
|
|
223
272
|
// If set, will preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.
|
|
224
273
|
preload?: false | 'intent'
|
|
225
|
-
// When preloaded, the preloaded result will be considered "fresh" for this duration in milliseconds
|
|
226
|
-
preloadMaxAge?: number
|
|
227
|
-
// When preloaded and subsequently inactive, the preloaded result will remain in memory for this duration in milliseconds
|
|
228
|
-
preloadGcMaxAge?: number
|
|
229
274
|
// Delay intent preloading by this many milliseconds. If the intent exits before this delay, the preload will be cancelled.
|
|
230
275
|
preloadDelay?: number
|
|
231
276
|
// If true, will render the link without the href attribute
|
|
@@ -233,58 +278,47 @@ export type LinkOptions<
|
|
|
233
278
|
}
|
|
234
279
|
|
|
235
280
|
export type CheckRelativePath<
|
|
236
|
-
|
|
281
|
+
TRouteTree extends AnyRoute,
|
|
237
282
|
TFrom,
|
|
238
283
|
TTo,
|
|
239
284
|
> = TTo extends string
|
|
240
285
|
? TFrom extends string
|
|
241
|
-
? ResolveRelativePath<TFrom, TTo> extends
|
|
286
|
+
? ResolveRelativePath<TFrom, TTo> extends RoutePaths<TRouteTree>
|
|
242
287
|
? {}
|
|
243
288
|
: {
|
|
244
289
|
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<
|
|
245
290
|
TFrom,
|
|
246
291
|
TTo
|
|
247
292
|
>}, which is not a valid route path.`
|
|
248
|
-
'Valid Route Paths':
|
|
293
|
+
'Valid Route Paths': RoutePaths<TRouteTree>
|
|
249
294
|
}
|
|
250
295
|
: {}
|
|
251
296
|
: {}
|
|
252
297
|
|
|
253
|
-
export type CheckPath<
|
|
254
|
-
TAllRouteInfo extends AnyAllRouteInfo,
|
|
298
|
+
export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<
|
|
255
299
|
TPath,
|
|
256
|
-
|
|
257
|
-
>
|
|
300
|
+
RoutePaths<TRouteTree>
|
|
301
|
+
> extends never
|
|
258
302
|
? TPass
|
|
259
|
-
: CheckPathError<
|
|
303
|
+
: CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>
|
|
260
304
|
|
|
261
|
-
export type CheckPathError<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
> = Expand<{
|
|
265
|
-
Error: `${TInvalids extends string
|
|
266
|
-
? TInvalids
|
|
267
|
-
: never} is not a valid route path.`
|
|
268
|
-
'Valid Route Paths': TAllRouteInfo['routePaths']
|
|
269
|
-
}>
|
|
305
|
+
export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
306
|
+
to: RoutePaths<TRouteTree>
|
|
307
|
+
}
|
|
270
308
|
|
|
271
|
-
export type CheckId<
|
|
272
|
-
TAllRouteInfo extends AnyAllRouteInfo,
|
|
309
|
+
export type CheckId<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<
|
|
273
310
|
TPath,
|
|
274
|
-
|
|
275
|
-
>
|
|
311
|
+
RouteIds<TRouteTree>
|
|
312
|
+
> extends never
|
|
276
313
|
? TPass
|
|
277
|
-
: CheckIdError<
|
|
314
|
+
: CheckIdError<TRouteTree, Exclude<TPath, RouteIds<TRouteTree>>>
|
|
278
315
|
|
|
279
|
-
export type CheckIdError<
|
|
280
|
-
TAllRouteInfo extends AnyAllRouteInfo,
|
|
281
|
-
TInvalids,
|
|
282
|
-
> = Expand<{
|
|
316
|
+
export type CheckIdError<TRouteTree extends AnyRoute, TInvalids> = {
|
|
283
317
|
Error: `${TInvalids extends string
|
|
284
318
|
? TInvalids
|
|
285
319
|
: never} is not a valid route ID.`
|
|
286
|
-
'Valid Route IDs':
|
|
287
|
-
}
|
|
320
|
+
'Valid Route IDs': RouteIds<TRouteTree>
|
|
321
|
+
}
|
|
288
322
|
|
|
289
323
|
export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string
|
|
290
324
|
? TTo extends string
|
|
@@ -309,11 +343,3 @@ export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string
|
|
|
309
343
|
: CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>
|
|
310
344
|
: never
|
|
311
345
|
: never
|
|
312
|
-
|
|
313
|
-
export type ValidFromPath<
|
|
314
|
-
TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
|
|
315
|
-
> =
|
|
316
|
-
| undefined
|
|
317
|
-
| (string extends TAllRouteInfo['routePaths']
|
|
318
|
-
? string
|
|
319
|
-
: TAllRouteInfo['routePaths'])
|