@tanstack/router-core 0.0.1-beta.157 → 0.0.1-beta.159
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/router.js +22 -28
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +22 -28
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +116 -116
- package/build/types/index.d.ts +10 -10
- package/build/umd/index.development.js +22 -28
- 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/router.ts +34 -39
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.159",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
45
|
"@gisatcz/cross-package-react-context": "^0.2.0",
|
|
46
|
-
"@tanstack/react-store": "0.0.1-beta.
|
|
46
|
+
"@tanstack/react-store": "0.0.1-beta.159"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "rollup --config rollup.config.js",
|
package/src/router.ts
CHANGED
|
@@ -74,7 +74,7 @@ export type RegisteredRouter = Register extends {
|
|
|
74
74
|
router: infer TRouter extends AnyRouter
|
|
75
75
|
}
|
|
76
76
|
? TRouter
|
|
77
|
-
:
|
|
77
|
+
: AnyRouter
|
|
78
78
|
|
|
79
79
|
export interface LocationState {}
|
|
80
80
|
|
|
@@ -107,7 +107,7 @@ export type HydrationCtx = {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export interface RouteMatch<
|
|
110
|
-
TRouteTree extends AnyRoute =
|
|
110
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
111
111
|
TRoute extends AnyRoute = Route,
|
|
112
112
|
> {
|
|
113
113
|
id: string
|
|
@@ -182,16 +182,16 @@ export interface RouterOptions<
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
export interface RouterState<
|
|
185
|
-
TRouteTree extends AnyRoute =
|
|
185
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
186
186
|
// TState extends LocationState = LocationState,
|
|
187
187
|
> {
|
|
188
188
|
status: 'idle' | 'pending'
|
|
189
189
|
isFetching: boolean
|
|
190
|
-
matchesById: Record<string, RouteMatch<
|
|
190
|
+
matchesById: Record<string, RouteMatch<TRouteTree, AnyRoute>>
|
|
191
191
|
matchIds: string[]
|
|
192
192
|
pendingMatchIds: string[]
|
|
193
|
-
matches: RouteMatch<
|
|
194
|
-
pendingMatches: RouteMatch<
|
|
193
|
+
matches: RouteMatch<TRouteTree, AnyRoute>[]
|
|
194
|
+
pendingMatches: RouteMatch<TRouteTree, AnyRoute>[]
|
|
195
195
|
location: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
196
196
|
resolvedLocation: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
197
197
|
lastUpdated: number
|
|
@@ -250,7 +250,7 @@ export const componentTypes = [
|
|
|
250
250
|
] as const
|
|
251
251
|
|
|
252
252
|
export class Router<
|
|
253
|
-
TRouteTree extends AnyRoute =
|
|
253
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
254
254
|
TDehydrated extends Record<string, any> = Record<string, any>,
|
|
255
255
|
> {
|
|
256
256
|
types!: {
|
|
@@ -641,43 +641,38 @@ export class Router<
|
|
|
641
641
|
if (routeCursor) matchedRoutes.unshift(routeCursor)
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
// Alright, by now we should have all of our
|
|
645
|
-
// matching routes and their param pairs, let's
|
|
646
|
-
// Turn them into actual `Match` objects and
|
|
647
|
-
// accumulate the params into a single params bag
|
|
648
|
-
let allParams = {}
|
|
649
|
-
|
|
650
644
|
// Existing matches are matches that are already loaded along with
|
|
651
645
|
// pending matches that are still loading
|
|
652
646
|
|
|
653
|
-
const
|
|
654
|
-
let parsedParams
|
|
647
|
+
const parseErrors = matchedRoutes.map((route) => {
|
|
655
648
|
let parsedParamsError
|
|
656
649
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
cause: err,
|
|
667
|
-
})
|
|
650
|
+
if (route.options.parseParams) {
|
|
651
|
+
try {
|
|
652
|
+
const parsedParams = route.options.parseParams(routeParams)
|
|
653
|
+
// Add the parsed params to the accumulated params bag
|
|
654
|
+
Object.assign(routeParams, parsedParams)
|
|
655
|
+
} catch (err: any) {
|
|
656
|
+
parsedParamsError = new PathParamError(err.message, {
|
|
657
|
+
cause: err,
|
|
658
|
+
})
|
|
668
659
|
|
|
669
|
-
|
|
670
|
-
|
|
660
|
+
if (opts?.throwOnError) {
|
|
661
|
+
throw parsedParamsError
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return parsedParamsError
|
|
671
665
|
}
|
|
672
666
|
}
|
|
673
667
|
|
|
674
|
-
|
|
675
|
-
|
|
668
|
+
return
|
|
669
|
+
})
|
|
676
670
|
|
|
677
|
-
|
|
671
|
+
const matches = matchedRoutes.map((route, index) => {
|
|
672
|
+
const interpolatedPath = interpolatePath(route.path, routeParams)
|
|
678
673
|
const key = route.options.key
|
|
679
674
|
? route.options.key({
|
|
680
|
-
params:
|
|
675
|
+
params: routeParams,
|
|
681
676
|
search: locationSearch,
|
|
682
677
|
}) ?? ''
|
|
683
678
|
: ''
|
|
@@ -685,7 +680,7 @@ export class Router<
|
|
|
685
680
|
const stringifiedKey = key ? JSON.stringify(key) : ''
|
|
686
681
|
|
|
687
682
|
const matchId =
|
|
688
|
-
interpolatePath(route.id,
|
|
683
|
+
interpolatePath(route.id, routeParams, true) + stringifiedKey
|
|
689
684
|
|
|
690
685
|
// Waste not, want not. If we already have a match for this route,
|
|
691
686
|
// reuse it. This is important for layout routes, which might stick
|
|
@@ -706,7 +701,7 @@ export class Router<
|
|
|
706
701
|
id: matchId,
|
|
707
702
|
key: stringifiedKey,
|
|
708
703
|
routeId: route.id,
|
|
709
|
-
params:
|
|
704
|
+
params: routeParams,
|
|
710
705
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
711
706
|
updatedAt: Date.now(),
|
|
712
707
|
invalidAt: Infinity,
|
|
@@ -717,7 +712,7 @@ export class Router<
|
|
|
717
712
|
isFetching: false,
|
|
718
713
|
invalid: false,
|
|
719
714
|
error: undefined,
|
|
720
|
-
paramsError:
|
|
715
|
+
paramsError: parseErrors[index],
|
|
721
716
|
searchError: undefined,
|
|
722
717
|
loaderData: undefined,
|
|
723
718
|
loadPromise: Promise.resolve(),
|
|
@@ -1129,7 +1124,7 @@ export class Router<
|
|
|
1129
1124
|
preload,
|
|
1130
1125
|
preloadDelay: userPreloadDelay,
|
|
1131
1126
|
disabled,
|
|
1132
|
-
state
|
|
1127
|
+
state,
|
|
1133
1128
|
}: LinkOptions<TRouteTree, TFrom, TTo>): LinkInfo => {
|
|
1134
1129
|
// If this link simply reloads the current route,
|
|
1135
1130
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1152,7 +1147,7 @@ export class Router<
|
|
|
1152
1147
|
params,
|
|
1153
1148
|
hash,
|
|
1154
1149
|
replace,
|
|
1155
|
-
state
|
|
1150
|
+
state,
|
|
1156
1151
|
}
|
|
1157
1152
|
|
|
1158
1153
|
const next = this.buildNext(nextOpts)
|
|
@@ -1740,7 +1735,7 @@ function isCtrlEvent(e: MouseEvent) {
|
|
|
1740
1735
|
export type AnyRedirect = Redirect<any, any, any>
|
|
1741
1736
|
|
|
1742
1737
|
export type Redirect<
|
|
1743
|
-
TRouteTree extends AnyRoute =
|
|
1738
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
1744
1739
|
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
1745
1740
|
TTo extends string = '',
|
|
1746
1741
|
> = NavigateOptions<TRouteTree, TFrom, TTo> & {
|
|
@@ -1748,7 +1743,7 @@ export type Redirect<
|
|
|
1748
1743
|
}
|
|
1749
1744
|
|
|
1750
1745
|
export function redirect<
|
|
1751
|
-
TRouteTree extends AnyRoute =
|
|
1746
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
1752
1747
|
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
1753
1748
|
TTo extends string = '',
|
|
1754
1749
|
>(opts: Redirect<TRouteTree, TFrom, TTo>): Redirect<TRouteTree, TFrom, TTo> {
|