@@ -2123,54 +2123,50 @@ export class RouterCore<
2123
2123
2124
2124
const handleRedirectAndNotFound = (
2125
2125
match : AnyRouteMatch | undefined ,
2126
- err : any ,
2126
+ err : unknown ,
2127
2127
) => {
2128
- if ( isRedirect ( err ) || isNotFound ( err ) ) {
2129
- if ( isRedirect ( err ) ) {
2130
- if ( err . redirectHandled ) {
2131
- if ( ! err . options . reloadDocument ) {
2132
- throw err
2133
- }
2134
- }
2135
- }
2128
+ if ( ! isRedirect ( err ) && ! isNotFound ( err ) ) return
2136
2129
2137
- // in case of a redirecting match during preload, the match does not exist
2138
- if ( match ) {
2139
- match . _nonReactive . beforeLoadPromise ?. resolve ( )
2140
- match . _nonReactive . loaderPromise ?. resolve ( )
2141
- match . _nonReactive . beforeLoadPromise = undefined
2142
- match . _nonReactive . loaderPromise = undefined
2143
-
2144
- updateMatch ( match . id , ( prev ) => ( {
2145
- ...prev ,
2146
- status : isRedirect ( err )
2147
- ? 'redirected'
2148
- : isNotFound ( err )
2149
- ? 'notFound'
2150
- : 'error' ,
2151
- isFetching : false ,
2152
- error : err ,
2153
- } ) )
2130
+ if (
2131
+ isRedirect ( err ) &&
2132
+ err . redirectHandled &&
2133
+ ! err . options . reloadDocument
2134
+ ) {
2135
+ throw err
2136
+ }
2154
2137
2155
- if ( ! ( err as any ) . routeId ) {
2156
- ; ( err as any ) . routeId = match . routeId
2157
- }
2138
+ // in case of a redirecting match during preload, the match does not exist
2139
+ if ( match ) {
2140
+ match . _nonReactive . beforeLoadPromise ?. resolve ( )
2141
+ match . _nonReactive . loaderPromise ?. resolve ( )
2142
+ match . _nonReactive . beforeLoadPromise = undefined
2143
+ match . _nonReactive . loaderPromise = undefined
2158
2144
2159
- match . _nonReactive . loadPromise ?. resolve ( )
2160
- }
2145
+ const status = isRedirect ( err ) ? 'redirected' : 'notFound'
2161
2146
2162
- if ( isRedirect ( err ) ) {
2163
- rendered = true
2164
- err . options . _fromLocation = location
2165
- err . redirectHandled = true
2166
- err = this . resolveRedirect ( err )
2167
- throw err
2168
- } else if ( isNotFound ( err ) ) {
2169
- this . _handleNotFound ( matches , err , {
2170
- updateMatch,
2171
- } )
2172
- throw err
2147
+ updateMatch ( match . id , ( prev ) => ( {
2148
+ ...prev ,
2149
+ status,
2150
+ isFetching : false ,
2151
+ error : err ,
2152
+ } ) )
2153
+
2154
+ if ( isNotFound ( err ) && ! err . routeId ) {
2155
+ err . routeId = match . routeId
2173
2156
}
2157
+
2158
+ match . _nonReactive . loadPromise ?. resolve ( )
2159
+ }
2160
+
2161
+ if ( isRedirect ( err ) ) {
2162
+ rendered = true
2163
+ err . options . _fromLocation = location
2164
+ err . redirectHandled = true
2165
+ err = this . resolveRedirect ( err )
2166
+ throw err
2167
+ } else {
2168
+ this . _handleNotFound ( matches , err , updateMatch )
2169
+ throw err
2174
2170
}
2175
2171
}
2176
2172
@@ -3063,14 +3059,10 @@ export class RouterCore<
3063
3059
_handleNotFound = (
3064
3060
matches : Array < AnyRouteMatch > ,
3065
3061
err : NotFoundError ,
3066
- {
3067
- updateMatch = this . updateMatch ,
3068
- } : {
3069
- updateMatch ?: (
3070
- id : string ,
3071
- updater : ( match : AnyRouteMatch ) => AnyRouteMatch ,
3072
- ) => void
3073
- } = { } ,
3062
+ updateMatch : (
3063
+ id : string ,
3064
+ updater : ( match : AnyRouteMatch ) => AnyRouteMatch ,
3065
+ ) => void = this . updateMatch ,
3074
3066
) => {
3075
3067
// Find the route that should handle the not found error
3076
3068
// First check if a specific route is requested to show the error
@@ -3116,9 +3108,7 @@ export class RouterCore<
3116
3108
3117
3109
if ( ( err as any ) . routerCode === 'BEFORE_LOAD' && routeCursor . parentRoute ) {
3118
3110
err . routeId = routeCursor . parentRoute . id
3119
- this . _handleNotFound ( matches , err , {
3120
- updateMatch,
3121
- } )
3111
+ this . _handleNotFound ( matches , err , updateMatch )
3122
3112
}
3123
3113
}
3124
3114
0 commit comments