@@ -2116,54 +2116,50 @@ export class RouterCore<
2116
2116
2117
2117
const handleRedirectAndNotFound = (
2118
2118
match : AnyRouteMatch | undefined ,
2119
- err : any ,
2119
+ err : unknown ,
2120
2120
) => {
2121
- if ( isRedirect ( err ) || isNotFound ( err ) ) {
2122
- if ( isRedirect ( err ) ) {
2123
- if ( err . redirectHandled ) {
2124
- if ( ! err . options . reloadDocument ) {
2125
- throw err
2126
- }
2127
- }
2128
- }
2121
+ if ( ! isRedirect ( err ) && ! isNotFound ( err ) ) return
2129
2122
2130
- // in case of a redirecting match during preload, the match does not exist
2131
- if ( match ) {
2132
- match . _nonReactive . beforeLoadPromise ?. resolve ( )
2133
- match . _nonReactive . loaderPromise ?. resolve ( )
2134
- match . _nonReactive . beforeLoadPromise = undefined
2135
- match . _nonReactive . loaderPromise = undefined
2136
-
2137
- updateMatch ( match . id , ( prev ) => ( {
2138
- ...prev ,
2139
- status : isRedirect ( err )
2140
- ? 'redirected'
2141
- : isNotFound ( err )
2142
- ? 'notFound'
2143
- : 'error' ,
2144
- isFetching : false ,
2145
- error : err ,
2146
- } ) )
2123
+ if (
2124
+ isRedirect ( err ) &&
2125
+ err . redirectHandled &&
2126
+ ! err . options . reloadDocument
2127
+ ) {
2128
+ throw err
2129
+ }
2147
2130
2148
- if ( ! ( err as any ) . routeId ) {
2149
- ; ( err as any ) . routeId = match . routeId
2150
- }
2131
+ // in case of a redirecting match during preload, the match does not exist
2132
+ if ( match ) {
2133
+ match . _nonReactive . beforeLoadPromise ?. resolve ( )
2134
+ match . _nonReactive . loaderPromise ?. resolve ( )
2135
+ match . _nonReactive . beforeLoadPromise = undefined
2136
+ match . _nonReactive . loaderPromise = undefined
2151
2137
2152
- match . _nonReactive . loadPromise ?. resolve ( )
2153
- }
2138
+ const status = isRedirect ( err ) ? 'redirected' : 'notFound'
2154
2139
2155
- if ( isRedirect ( err ) ) {
2156
- rendered = true
2157
- err . options . _fromLocation = location
2158
- err . redirectHandled = true
2159
- err = this . resolveRedirect ( err )
2160
- throw err
2161
- } else if ( isNotFound ( err ) ) {
2162
- this . _handleNotFound ( matches , err , {
2163
- updateMatch,
2164
- } )
2165
- throw err
2140
+ updateMatch ( match . id , ( prev ) => ( {
2141
+ ...prev ,
2142
+ status,
2143
+ isFetching : false ,
2144
+ error : err ,
2145
+ } ) )
2146
+
2147
+ if ( isNotFound ( err ) && ! err . routeId ) {
2148
+ err . routeId = match . routeId
2166
2149
}
2150
+
2151
+ match . _nonReactive . loadPromise ?. resolve ( )
2152
+ }
2153
+
2154
+ if ( isRedirect ( err ) ) {
2155
+ rendered = true
2156
+ err . options . _fromLocation = location
2157
+ err . redirectHandled = true
2158
+ err = this . resolveRedirect ( err )
2159
+ throw err
2160
+ } else {
2161
+ this . _handleNotFound ( matches , err , updateMatch )
2162
+ throw err
2167
2163
}
2168
2164
}
2169
2165
@@ -3056,14 +3052,10 @@ export class RouterCore<
3056
3052
_handleNotFound = (
3057
3053
matches : Array < AnyRouteMatch > ,
3058
3054
err : NotFoundError ,
3059
- {
3060
- updateMatch = this . updateMatch ,
3061
- } : {
3062
- updateMatch ?: (
3063
- id : string ,
3064
- updater : ( match : AnyRouteMatch ) => AnyRouteMatch ,
3065
- ) => void
3066
- } = { } ,
3055
+ updateMatch : (
3056
+ id : string ,
3057
+ updater : ( match : AnyRouteMatch ) => AnyRouteMatch ,
3058
+ ) => void = this . updateMatch ,
3067
3059
) => {
3068
3060
// Find the route that should handle the not found error
3069
3061
// First check if a specific route is requested to show the error
@@ -3109,9 +3101,7 @@ export class RouterCore<
3109
3101
3110
3102
if ( ( err as any ) . routerCode === 'BEFORE_LOAD' && routeCursor . parentRoute ) {
3111
3103
err . routeId = routeCursor . parentRoute . id
3112
- this . _handleNotFound ( matches , err , {
3113
- updateMatch,
3114
- } )
3104
+ this . _handleNotFound ( matches , err , updateMatch )
3115
3105
}
3116
3106
}
3117
3107
0 commit comments