@tanstack/router-core 0.0.1-beta.156 → 0.0.1-beta.158
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/cjs/searchParams.js +25 -8
- package/build/cjs/searchParams.js.map +1 -1
- package/build/esm/index.js +47 -36
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +118 -118
- package/build/types/index.d.ts +2 -2
- package/build/umd/index.development.js +47 -36
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +25 -30
- package/src/searchParams.ts +32 -8
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.158",
|
|
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.158"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "rollup --config rollup.config.js",
|
package/src/router.ts
CHANGED
|
@@ -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)
|
package/src/searchParams.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { decode, encode } from './qss'
|
|
|
2
2
|
import { AnySearchSchema } from './route'
|
|
3
3
|
|
|
4
4
|
export const defaultParseSearch = parseSearchWith(JSON.parse)
|
|
5
|
-
export const defaultStringifySearch = stringifySearchWith(
|
|
5
|
+
export const defaultStringifySearch = stringifySearchWith(
|
|
6
|
+
JSON.stringify,
|
|
7
|
+
JSON.parse,
|
|
8
|
+
)
|
|
6
9
|
|
|
7
10
|
export function parseSearchWith(parser: (str: string) => any) {
|
|
8
11
|
return (searchStr: string): AnySearchSchema => {
|
|
@@ -28,7 +31,30 @@ export function parseSearchWith(parser: (str: string) => any) {
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
export function stringifySearchWith(
|
|
34
|
+
export function stringifySearchWith(
|
|
35
|
+
stringify: (search: any) => string,
|
|
36
|
+
parser?: (str: string) => any,
|
|
37
|
+
) {
|
|
38
|
+
function stringifyValue(val: any) {
|
|
39
|
+
if (typeof val === 'object' && val !== null) {
|
|
40
|
+
try {
|
|
41
|
+
return stringify(val)
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// silent
|
|
44
|
+
}
|
|
45
|
+
} else if (typeof val === 'string' && typeof parser === 'function') {
|
|
46
|
+
try {
|
|
47
|
+
// Check if it's a valid parseable string.
|
|
48
|
+
// If it is, then stringify it again.
|
|
49
|
+
parser(val)
|
|
50
|
+
return stringify(val)
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// silent
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return val
|
|
56
|
+
}
|
|
57
|
+
|
|
32
58
|
return (search: Record<string, any>) => {
|
|
33
59
|
search = { ...search }
|
|
34
60
|
|
|
@@ -37,12 +63,10 @@ export function stringifySearchWith(stringify: (search: any) => string) {
|
|
|
37
63
|
const val = search[key]
|
|
38
64
|
if (typeof val === 'undefined' || val === undefined) {
|
|
39
65
|
delete search[key]
|
|
40
|
-
} else if (val
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// silent
|
|
45
|
-
}
|
|
66
|
+
} else if (Array.isArray(val)) {
|
|
67
|
+
search[key] = val.map(stringifyValue)
|
|
68
|
+
} else {
|
|
69
|
+
search[key] = stringifyValue(val)
|
|
46
70
|
}
|
|
47
71
|
})
|
|
48
72
|
}
|