@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/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.147",
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.147"
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(this.basepath, pathname, {
635
- to: route.fullPath,
636
- caseSensitive:
637
- route.options.caseSensitive ?? this.options.caseSensitive,
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
- await Promise.all(
838
- resolvedMatches.map(async (match, index) => {
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
- if (!opts?.preload) {
842
- // Update each match with its latest url data
843
- this.setRouteMatch(match.id, (s) => ({
844
- ...s,
845
- routeSearch: match.routeSearch,
846
- search: match.search,
847
- routeContext: match.routeContext,
848
- context: match.context,
849
- error: match.error,
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
- const handleError = (
857
- err: any,
858
- handler: undefined | ((err: any) => void),
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(err)) {
864
- throw err
877
+ if (isRedirect(errorHandlerErr)) {
878
+ throw errorHandlerErr
865
879
  }
880
+ }
866
881
 
867
- try {
868
- handler?.(err)
869
- } catch (errorHandlerErr) {
870
- err = errorHandlerErr
882
+ this.setRouteMatch(match.id, (s) => ({
883
+ ...s,
884
+ error: err,
885
+ status: 'error',
886
+ updatedAt: Date.now(),
887
+ }))
888
+ }
871
889
 
872
- if (isRedirect(errorHandlerErr)) {
873
- throw errorHandlerErr
874
- }
875
- }
890
+ if (match.paramsError) {
891
+ handleError(match.paramsError, route.options.onParseParamsError)
892
+ }
876
893
 
877
- this.setRouteMatch(match.id, (s) => ({
878
- ...s,
879
- error: err,
880
- status: 'error',
881
- updatedAt: Date.now(),
882
- }))
883
- }
894
+ if (match.searchError) {
895
+ handleError(match.searchError, route.options.onValidateSearchError)
896
+ }
884
897
 
885
- if (match.paramsError) {
886
- handleError(match.paramsError, route.options.onParseParamsError)
887
- }
898
+ let didError = false
888
899
 
889
- if (match.searchError) {
890
- handleError(match.searchError, route.options.onValidateSearchError)
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
- try {
894
- await route.options.beforeLoad?.({
895
- ...match,
896
- preload: !!opts?.preload,
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)