@tanstack/react-router 0.0.1-beta.225 → 0.0.1-beta.227
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/Matches.js +8 -6
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +1 -26
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +54 -54
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +62 -86
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +291 -285
- package/build/types/Matches.d.ts +0 -1
- package/build/types/RouterProvider.d.ts +1 -6
- package/build/types/fileRoute.d.ts +2 -2
- package/build/types/route.d.ts +7 -3
- package/build/types/router.d.ts +7 -3
- package/build/umd/index.development.js +62 -86
- 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 +2 -2
- package/src/Matches.tsx +21 -23
- package/src/RouterProvider.tsx +10 -79
- package/src/fileRoute.ts +7 -6
- package/src/route.ts +39 -39
- package/src/router.ts +95 -88
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.227",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
|
-
"@tanstack/history": "0.0.1-beta.
|
|
45
|
+
"@tanstack/history": "0.0.1-beta.227"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
RoutePaths,
|
|
15
15
|
} from './routeInfo'
|
|
16
16
|
import { RegisteredRouter } from './router'
|
|
17
|
-
import { NoInfer, StrictOrFrom } from './utils'
|
|
17
|
+
import { NoInfer, StrictOrFrom, pick } from './utils'
|
|
18
18
|
|
|
19
19
|
export interface RouteMatch<
|
|
20
20
|
TRouteTree extends AnyRoute = AnyRoute,
|
|
@@ -35,7 +35,6 @@ export interface RouteMatch<
|
|
|
35
35
|
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
|
|
36
36
|
__resolveLoadPromise?: () => void
|
|
37
37
|
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
38
|
-
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
|
|
39
38
|
search: FullSearchSchema<TRouteTree> &
|
|
40
39
|
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
|
41
40
|
fetchedAt: number
|
|
@@ -85,7 +84,6 @@ export function Matches() {
|
|
|
85
84
|
)
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
const defaultPending = () => null
|
|
89
87
|
function SafeFragment(props: any) {
|
|
90
88
|
return <>{props.children}</>
|
|
91
89
|
}
|
|
@@ -98,17 +96,17 @@ export function Match({ matches }: { matches: RouteMatch[] }) {
|
|
|
98
96
|
const locationKey = useRouterState().location.state?.key
|
|
99
97
|
|
|
100
98
|
const PendingComponent = (route.options.pendingComponent ??
|
|
101
|
-
options.defaultPendingComponent
|
|
102
|
-
defaultPending) as any
|
|
99
|
+
options.defaultPendingComponent) as any
|
|
103
100
|
|
|
104
101
|
const routeErrorComponent =
|
|
105
102
|
route.options.errorComponent ??
|
|
106
103
|
options.defaultErrorComponent ??
|
|
107
104
|
ErrorComponent
|
|
108
105
|
|
|
109
|
-
const ResolvedSuspenseBoundary =
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
const ResolvedSuspenseBoundary =
|
|
107
|
+
route.options.wrapInSuspense ?? PendingComponent
|
|
108
|
+
? React.Suspense
|
|
109
|
+
: SafeFragment
|
|
112
110
|
|
|
113
111
|
const errorComponent = routeErrorComponent
|
|
114
112
|
? React.useCallback(
|
|
@@ -125,6 +123,8 @@ export function Match({ matches }: { matches: RouteMatch[] }) {
|
|
|
125
123
|
)
|
|
126
124
|
: undefined
|
|
127
125
|
|
|
126
|
+
const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment
|
|
127
|
+
|
|
128
128
|
return (
|
|
129
129
|
<matchesContext.Provider value={matches}>
|
|
130
130
|
<ResolvedSuspenseBoundary
|
|
@@ -135,21 +135,15 @@ export function Match({ matches }: { matches: RouteMatch[] }) {
|
|
|
135
135
|
useParams: route.useParams,
|
|
136
136
|
})}
|
|
137
137
|
>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
</CatchBoundary>
|
|
148
|
-
) : (
|
|
149
|
-
<SafeFragment>
|
|
150
|
-
<MatchInner match={match} />
|
|
151
|
-
</SafeFragment>
|
|
152
|
-
)}
|
|
138
|
+
<ResolvedCatchBoundary
|
|
139
|
+
resetKey={locationKey}
|
|
140
|
+
errorComponent={errorComponent}
|
|
141
|
+
onCatch={() => {
|
|
142
|
+
warning(false, `Error in route match: ${match.id}`)
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
<MatchInner match={match} />
|
|
146
|
+
</ResolvedCatchBoundary>
|
|
153
147
|
</ResolvedSuspenseBoundary>
|
|
154
148
|
</matchesContext.Provider>
|
|
155
149
|
)
|
|
@@ -158,6 +152,10 @@ function MatchInner({ match }: { match: RouteMatch }): any {
|
|
|
158
152
|
const { options, routesById } = useRouter()
|
|
159
153
|
const route = routesById[match.routeId]!
|
|
160
154
|
|
|
155
|
+
if (match.id.split('/').length === 4) {
|
|
156
|
+
console.log(match.id, pick(match, ['status', 'cause', 'isFetching']))
|
|
157
|
+
}
|
|
158
|
+
|
|
161
159
|
if (match.status === 'error') {
|
|
162
160
|
throw match.error
|
|
163
161
|
}
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HistoryLocation,
|
|
3
|
-
HistoryState,
|
|
4
|
-
RouterHistory,
|
|
5
|
-
createBrowserHistory,
|
|
6
|
-
} from '@tanstack/history'
|
|
7
1
|
import * as React from 'react'
|
|
8
|
-
import invariant from 'tiny-invariant'
|
|
9
2
|
import warning from 'tiny-warning'
|
|
10
3
|
import { Matches } from './Matches'
|
|
11
4
|
import {
|
|
@@ -16,53 +9,18 @@ import {
|
|
|
16
9
|
ToOptions,
|
|
17
10
|
} from './link'
|
|
18
11
|
import { ParsedLocation } from './location'
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
interpolatePath,
|
|
22
|
-
joinPaths,
|
|
23
|
-
matchPathname,
|
|
24
|
-
parsePathname,
|
|
25
|
-
resolvePath,
|
|
26
|
-
trimPath,
|
|
27
|
-
trimPathRight,
|
|
28
|
-
} from './path'
|
|
29
|
-
import { isRedirect } from './redirects'
|
|
30
|
-
import {
|
|
31
|
-
AnyPathParams,
|
|
32
|
-
AnyRoute,
|
|
33
|
-
AnySearchSchema,
|
|
34
|
-
LoaderFnContext,
|
|
35
|
-
Route,
|
|
36
|
-
} from './route'
|
|
37
|
-
import {
|
|
38
|
-
FullSearchSchema,
|
|
39
|
-
RouteById,
|
|
40
|
-
RoutePaths,
|
|
41
|
-
RoutesById,
|
|
42
|
-
RoutesByPath,
|
|
43
|
-
} from './routeInfo'
|
|
12
|
+
import { AnyRoute } from './route'
|
|
13
|
+
import { RouteById, RoutePaths } from './routeInfo'
|
|
44
14
|
import {
|
|
45
15
|
BuildNextOptions,
|
|
46
|
-
DehydratedRouteMatch,
|
|
47
16
|
RegisteredRouter,
|
|
48
17
|
Router,
|
|
49
18
|
RouterOptions,
|
|
50
19
|
RouterState,
|
|
51
|
-
componentTypes,
|
|
52
20
|
} from './router'
|
|
53
|
-
import {
|
|
54
|
-
NoInfer,
|
|
55
|
-
PickAsRequired,
|
|
56
|
-
functionalUpdate,
|
|
57
|
-
last,
|
|
58
|
-
deepEqual,
|
|
59
|
-
pick,
|
|
60
|
-
replaceEqualDeep,
|
|
61
|
-
useStableCallback,
|
|
62
|
-
escapeJSON,
|
|
63
|
-
} from './utils'
|
|
21
|
+
import { NoInfer, PickAsRequired } from './utils'
|
|
64
22
|
import { MatchRouteOptions } from './Matches'
|
|
65
|
-
import {
|
|
23
|
+
import { RouteMatch } from './Matches'
|
|
66
24
|
|
|
67
25
|
export interface CommitLocationOptions {
|
|
68
26
|
replace?: boolean
|
|
@@ -102,43 +60,12 @@ export type MatchRouteFn<TRouteTree extends AnyRoute> = <
|
|
|
102
60
|
opts?: MatchRouteOptions,
|
|
103
61
|
) => false | RouteById<TRouteTree, TResolved>['types']['allParams']
|
|
104
62
|
|
|
105
|
-
export type LoadFn = (opts?: {
|
|
106
|
-
next?: ParsedLocation
|
|
107
|
-
throwOnError?: boolean
|
|
108
|
-
__dehydratedMatches?: DehydratedRouteMatch[]
|
|
109
|
-
}) => Promise<void>
|
|
110
|
-
|
|
111
63
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (
|
|
112
64
|
opts: BuildNextOptions,
|
|
113
65
|
) => ParsedLocation
|
|
114
66
|
|
|
115
67
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string)
|
|
116
68
|
|
|
117
|
-
// export type RouterContext<
|
|
118
|
-
// TRouteTree extends AnyRoute,
|
|
119
|
-
// // TDehydrated extends Record<string, any>,
|
|
120
|
-
// > = {
|
|
121
|
-
// buildLink: BuildLinkFn<TRouteTree>
|
|
122
|
-
// state: RouterState<TRouteTree>
|
|
123
|
-
// navigate: NavigateFn<TRouteTree>
|
|
124
|
-
// matchRoute: MatchRouteFn<TRouteTree>
|
|
125
|
-
// routeTree: TRouteTree
|
|
126
|
-
// routesById: RoutesById<TRouteTree>
|
|
127
|
-
// options: RouterOptions<TRouteTree>
|
|
128
|
-
// history: RouterHistory
|
|
129
|
-
// load: LoadFn
|
|
130
|
-
// buildLocation: BuildLocationFn<TRouteTree>
|
|
131
|
-
// subscribe: Router<TRouteTree>['subscribe']
|
|
132
|
-
// resetNextScrollRef: React.MutableRefObject<boolean>
|
|
133
|
-
// injectedHtmlRef: React.MutableRefObject<InjectedHtmlEntry[]>
|
|
134
|
-
// injectHtml: (entry: InjectedHtmlEntry) => void
|
|
135
|
-
// dehydrateData: <T>(
|
|
136
|
-
// key: any,
|
|
137
|
-
// getData: T | (() => Promise<T> | T),
|
|
138
|
-
// ) => () => void
|
|
139
|
-
// hydrateData: <T>(key: any) => T | undefined
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
69
|
export const routerContext = React.createContext<Router<any>>(null!)
|
|
143
70
|
|
|
144
71
|
if (typeof document !== 'undefined') {
|
|
@@ -170,11 +97,15 @@ export function RouterProvider<
|
|
|
170
97
|
router.updateOptions({
|
|
171
98
|
...router.options,
|
|
172
99
|
...rest,
|
|
100
|
+
|
|
173
101
|
context: {
|
|
174
102
|
...router.options.context,
|
|
175
103
|
...rest?.context,
|
|
176
104
|
},
|
|
177
|
-
} as PickAsRequired<
|
|
105
|
+
} as PickAsRequired<
|
|
106
|
+
RouterOptions<TRouteTree, TDehydrated>,
|
|
107
|
+
'stringifySearch' | 'parseSearch' | 'context'
|
|
108
|
+
>)
|
|
178
109
|
|
|
179
110
|
const [preState, setState] = React.useState(() => router.state)
|
|
180
111
|
const [isTransitioning, startReactTransition] = React.useTransition()
|
|
@@ -222,7 +153,7 @@ export function RouterProvider<
|
|
|
222
153
|
return () => {
|
|
223
154
|
unsub()
|
|
224
155
|
}
|
|
225
|
-
}, [history])
|
|
156
|
+
}, [router.history])
|
|
226
157
|
|
|
227
158
|
React.useLayoutEffect(() => {
|
|
228
159
|
if (!isTransitioning && state.resolvedLocation !== state.location) {
|
package/src/fileRoute.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
TrimPathLeft,
|
|
15
15
|
RouteConstraints,
|
|
16
16
|
} from './route'
|
|
17
|
-
import { Assign,
|
|
17
|
+
import { Assign, Expand, IsAny } from './utils'
|
|
18
18
|
|
|
19
19
|
export interface FileRoutesByPath {
|
|
20
20
|
// '/': {
|
|
@@ -86,13 +86,14 @@ export class FileRoute<
|
|
|
86
86
|
|
|
87
87
|
createRoute = <
|
|
88
88
|
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
89
|
-
TFullSearchSchema extends
|
|
89
|
+
TFullSearchSchema extends
|
|
90
|
+
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
90
91
|
TParentRoute,
|
|
91
92
|
TSearchSchema
|
|
92
93
|
>,
|
|
93
|
-
TParams extends RouteConstraints['TParams'] =
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
TParams extends RouteConstraints['TParams'] = Expand<
|
|
95
|
+
Record<ParsePathParams<TPath>, string>
|
|
96
|
+
>,
|
|
96
97
|
TAllParams extends RouteConstraints['TAllParams'] = MergeFromFromParent<
|
|
97
98
|
TParentRoute['types']['allParams'],
|
|
98
99
|
TParams
|
|
@@ -112,7 +113,7 @@ export class FileRoute<
|
|
|
112
113
|
RouteOptions<
|
|
113
114
|
TParentRoute,
|
|
114
115
|
string,
|
|
115
|
-
|
|
116
|
+
TPath,
|
|
116
117
|
TSearchSchema,
|
|
117
118
|
TFullSearchSchema,
|
|
118
119
|
TParams,
|
package/src/route.ts
CHANGED
|
@@ -76,13 +76,11 @@ export type RouteOptions<
|
|
|
76
76
|
TAllContext,
|
|
77
77
|
TLoaderData
|
|
78
78
|
> &
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
TLoaderData
|
|
85
|
-
>
|
|
79
|
+
UpdatableRouteOptions<
|
|
80
|
+
NoInfer<TFullSearchSchema>,
|
|
81
|
+
NoInfer<TAllParams>,
|
|
82
|
+
NoInfer<TAllContext>,
|
|
83
|
+
NoInfer<TLoaderData>
|
|
86
84
|
>
|
|
87
85
|
|
|
88
86
|
export type ParamsFallback<
|
|
@@ -139,7 +137,8 @@ export type BaseRouteOptions<
|
|
|
139
137
|
TRouteContext
|
|
140
138
|
>
|
|
141
139
|
}) & {
|
|
142
|
-
|
|
140
|
+
key?: (opts: { search: TFullSearchSchema; location: ParsedLocation }) => any
|
|
141
|
+
loader?: RouteLoaderFn<
|
|
143
142
|
TAllParams,
|
|
144
143
|
TFullSearchSchema,
|
|
145
144
|
NoInfer<TAllContext>,
|
|
@@ -267,7 +266,7 @@ export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
|
|
|
267
266
|
[Key in keyof TParentParams]?: DefinedPathParamWarning
|
|
268
267
|
}
|
|
269
268
|
|
|
270
|
-
export type
|
|
269
|
+
export type RouteLoaderFn<
|
|
271
270
|
TAllParams = {},
|
|
272
271
|
TFullSearchSchema extends Record<string, any> = {},
|
|
273
272
|
TAllContext extends Record<string, any> = AnyContext,
|
|
@@ -389,7 +388,8 @@ export class Route<
|
|
|
389
388
|
TPath
|
|
390
389
|
>,
|
|
391
390
|
TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
|
|
392
|
-
TFullSearchSchema extends
|
|
391
|
+
TFullSearchSchema extends
|
|
392
|
+
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
393
393
|
TParentRoute,
|
|
394
394
|
TSearchSchema
|
|
395
395
|
>,
|
|
@@ -714,14 +714,14 @@ type RoutePrefix<
|
|
|
714
714
|
> = string extends TPath
|
|
715
715
|
? RootRouteId
|
|
716
716
|
: TPath extends string
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
717
|
+
? TPrefix extends RootRouteId
|
|
718
|
+
? TPath extends '/'
|
|
719
|
+
? '/'
|
|
720
|
+
: `/${TrimPath<TPath>}`
|
|
721
|
+
: `${TPrefix}/${TPath}` extends '/'
|
|
722
|
+
? '/'
|
|
723
|
+
: `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
|
|
724
|
+
: never
|
|
725
725
|
|
|
726
726
|
export type TrimPath<T extends string> = '' extends T
|
|
727
727
|
? ''
|
|
@@ -731,13 +731,13 @@ export type TrimPathLeft<T extends string> =
|
|
|
731
731
|
T extends `${RootRouteId}/${infer U}`
|
|
732
732
|
? TrimPathLeft<U>
|
|
733
733
|
: T extends `/${infer U}`
|
|
734
|
-
|
|
735
|
-
|
|
734
|
+
? TrimPathLeft<U>
|
|
735
|
+
: T
|
|
736
736
|
export type TrimPathRight<T extends string> = T extends '/'
|
|
737
737
|
? '/'
|
|
738
738
|
: T extends `${infer U}/`
|
|
739
|
-
|
|
740
|
-
|
|
739
|
+
? TrimPathRight<U>
|
|
740
|
+
: T
|
|
741
741
|
|
|
742
742
|
export type RouteMask<TRouteTree extends AnyRoute> = {
|
|
743
743
|
routeTree: TRouteTree
|
|
@@ -842,20 +842,20 @@ export type ComponentPropsFromRoute<TRoute> =
|
|
|
842
842
|
TRoute extends (() => infer T extends AnyRoute)
|
|
843
843
|
? ComponentPropsFromRoute<T>
|
|
844
844
|
: TRoute extends Route<
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
845
|
+
infer TParentRoute,
|
|
846
|
+
infer TPath,
|
|
847
|
+
infer TFullPath,
|
|
848
|
+
infer TCustomId,
|
|
849
|
+
infer TId,
|
|
850
|
+
infer TSearchSchema,
|
|
851
|
+
infer TFullSearchSchema,
|
|
852
|
+
infer TParams,
|
|
853
|
+
infer TAllParams,
|
|
854
|
+
infer TRouteContext,
|
|
855
|
+
infer TAllContext,
|
|
856
|
+
infer TRouterContext,
|
|
857
|
+
infer TLoaderData,
|
|
858
|
+
infer TChildren
|
|
859
|
+
>
|
|
860
|
+
? RouteProps<TFullSearchSchema, TAllParams, TAllContext, TLoaderData>
|
|
861
|
+
: {}
|