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