@tanstack/router-core 0.0.1-beta.147 → 0.0.1-beta.149
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 +26 -17
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +26 -17
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +116 -116
- package/build/umd/index.development.js +26 -17
- 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 +72 -60
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.149",
|
|
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.149"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "rollup --config rollup.config.js",
|
package/src/router.ts
CHANGED
|
@@ -631,11 +631,15 @@ export class Router<
|
|
|
631
631
|
let routeParams: AnyPathParams = {}
|
|
632
632
|
|
|
633
633
|
let foundRoute = this.flatRoutes.find((route) => {
|
|
634
|
-
const matchedParams = matchPathname(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
634
|
+
const matchedParams = matchPathname(
|
|
635
|
+
this.basepath,
|
|
636
|
+
trimPathRight(pathname),
|
|
637
|
+
{
|
|
638
|
+
to: route.fullPath,
|
|
639
|
+
caseSensitive:
|
|
640
|
+
route.options.caseSensitive ?? this.options.caseSensitive,
|
|
641
|
+
},
|
|
642
|
+
)
|
|
639
643
|
|
|
640
644
|
if (matchedParams) {
|
|
641
645
|
routeParams = matchedParams
|
|
@@ -830,76 +834,84 @@ export class Router<
|
|
|
830
834
|
) => {
|
|
831
835
|
this.cleanMatches()
|
|
832
836
|
|
|
837
|
+
if (!opts?.preload) {
|
|
838
|
+
resolvedMatches.forEach((match) => {
|
|
839
|
+
// Update each match with its latest url data
|
|
840
|
+
this.setRouteMatch(match.id, (s) => ({
|
|
841
|
+
...s,
|
|
842
|
+
routeSearch: match.routeSearch,
|
|
843
|
+
search: match.search,
|
|
844
|
+
routeContext: match.routeContext,
|
|
845
|
+
context: match.context,
|
|
846
|
+
error: match.error,
|
|
847
|
+
paramsError: match.paramsError,
|
|
848
|
+
searchError: match.searchError,
|
|
849
|
+
params: match.params,
|
|
850
|
+
}))
|
|
851
|
+
})
|
|
852
|
+
}
|
|
853
|
+
|
|
833
854
|
let firstBadMatchIndex: number | undefined
|
|
834
855
|
|
|
835
856
|
// Check each match middleware to see if the route can be accessed
|
|
836
857
|
try {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const route = this.getRoute(match.routeId)
|
|
858
|
+
for (const [index, match] of resolvedMatches.entries()) {
|
|
859
|
+
const route = this.getRoute(match.routeId)
|
|
840
860
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
paramsError: match.paramsError,
|
|
851
|
-
searchError: match.searchError,
|
|
852
|
-
params: match.params,
|
|
853
|
-
}))
|
|
861
|
+
const handleError = (
|
|
862
|
+
err: any,
|
|
863
|
+
handler: undefined | ((err: any) => void),
|
|
864
|
+
) => {
|
|
865
|
+
firstBadMatchIndex = firstBadMatchIndex ?? index
|
|
866
|
+
handler = handler || route.options.onError
|
|
867
|
+
|
|
868
|
+
if (isRedirect(err)) {
|
|
869
|
+
throw err
|
|
854
870
|
}
|
|
855
871
|
|
|
856
|
-
|
|
857
|
-
err
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
firstBadMatchIndex = firstBadMatchIndex ?? index
|
|
861
|
-
handler = handler || route.options.onError
|
|
872
|
+
try {
|
|
873
|
+
handler?.(err)
|
|
874
|
+
} catch (errorHandlerErr) {
|
|
875
|
+
err = errorHandlerErr
|
|
862
876
|
|
|
863
|
-
if (isRedirect(
|
|
864
|
-
throw
|
|
877
|
+
if (isRedirect(errorHandlerErr)) {
|
|
878
|
+
throw errorHandlerErr
|
|
865
879
|
}
|
|
880
|
+
}
|
|
866
881
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
882
|
+
this.setRouteMatch(match.id, (s) => ({
|
|
883
|
+
...s,
|
|
884
|
+
error: err,
|
|
885
|
+
status: 'error',
|
|
886
|
+
updatedAt: Date.now(),
|
|
887
|
+
}))
|
|
888
|
+
}
|
|
871
889
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
}
|
|
890
|
+
if (match.paramsError) {
|
|
891
|
+
handleError(match.paramsError, route.options.onParseParamsError)
|
|
892
|
+
}
|
|
876
893
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
status: 'error',
|
|
881
|
-
updatedAt: Date.now(),
|
|
882
|
-
}))
|
|
883
|
-
}
|
|
894
|
+
if (match.searchError) {
|
|
895
|
+
handleError(match.searchError, route.options.onValidateSearchError)
|
|
896
|
+
}
|
|
884
897
|
|
|
885
|
-
|
|
886
|
-
handleError(match.paramsError, route.options.onParseParamsError)
|
|
887
|
-
}
|
|
898
|
+
let didError = false
|
|
888
899
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
900
|
+
try {
|
|
901
|
+
await route.options.beforeLoad?.({
|
|
902
|
+
...match,
|
|
903
|
+
preload: !!opts?.preload,
|
|
904
|
+
})
|
|
905
|
+
} catch (err) {
|
|
906
|
+
handleError(err, route.options.onBeforeLoadError)
|
|
907
|
+
didError = true
|
|
908
|
+
}
|
|
892
909
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
} catch (err) {
|
|
899
|
-
handleError(err, route.options.onBeforeLoadError)
|
|
900
|
-
}
|
|
901
|
-
}),
|
|
902
|
-
)
|
|
910
|
+
// If we errored, do not run the next matches' middleware
|
|
911
|
+
if (didError) {
|
|
912
|
+
break
|
|
913
|
+
}
|
|
914
|
+
}
|
|
903
915
|
} catch (err) {
|
|
904
916
|
if (!opts?.preload) {
|
|
905
917
|
this.navigate(err as any)
|