@@ -2237,56 +2237,27 @@ export function createRouter(init: RouterInit): Router {
2237
2237
matches = fogOfWar . matches ;
2238
2238
}
2239
2239
2240
+ if ( ! matches ) {
2241
+ setFetcherError (
2242
+ key ,
2243
+ routeId ,
2244
+ getInternalRouterError ( 404 , { pathname : normalizedPath } ) ,
2245
+ { flushSync }
2246
+ ) ;
2247
+ return ;
2248
+ }
2249
+
2240
2250
let { path, submission, error } = normalizeNavigateOptions (
2241
2251
true ,
2242
2252
normalizedPath ,
2243
2253
opts
2244
2254
) ;
2245
2255
2246
- let abortController = new AbortController ( ) ;
2247
-
2248
- if ( ! matches ) {
2249
- if ( ! fogOfWar . active ) {
2250
- setFetcherError (
2251
- key ,
2252
- routeId ,
2253
- getInternalRouterError ( 404 , { pathname : normalizedPath } ) ,
2254
- { flushSync }
2255
- ) ;
2256
- return ;
2257
- } else {
2258
- let discoverResult = await discoverRoutes (
2259
- matches ?? [ ] ,
2260
- path ,
2261
- abortController . signal ,
2262
- key
2263
- ) ;
2264
-
2265
- if ( discoverResult . type === "aborted" ) {
2266
- return ;
2267
- } else if ( discoverResult . type === "error" ) {
2268
- setFetcherError ( key , routeId , discoverResult . error , { flushSync } ) ;
2269
- return ;
2270
- } else if ( ! discoverResult . matches ) {
2271
- setFetcherError (
2272
- key ,
2273
- routeId ,
2274
- getInternalRouterError ( 404 , { pathname : path } ) ,
2275
- { flushSync }
2276
- ) ;
2277
- return ;
2278
- } else {
2279
- matches = discoverResult . matches ;
2280
- }
2281
- }
2282
- }
2283
-
2284
2256
if ( error ) {
2285
2257
setFetcherError ( key , routeId , error , { flushSync } ) ;
2286
2258
return ;
2287
2259
}
2288
2260
2289
- let match = getTargetMatch ( matches , path ) ;
2290
2261
// Create a new context per fetch
2291
2262
let scopedContext = new unstable_RouterContextProvider (
2292
2263
init . unstable_getContext ? await init . unstable_getContext ( ) : undefined
@@ -2298,10 +2269,9 @@ export function createRouter(init: RouterInit): Router {
2298
2269
key ,
2299
2270
routeId ,
2300
2271
path ,
2301
- match ,
2302
2272
matches ,
2303
2273
scopedContext ,
2304
- abortController ,
2274
+ fogOfWar . active ,
2305
2275
flushSync ,
2306
2276
preventScrollReset ,
2307
2277
submission
@@ -2316,10 +2286,9 @@ export function createRouter(init: RouterInit): Router {
2316
2286
key ,
2317
2287
routeId ,
2318
2288
path ,
2319
- match ,
2320
2289
matches ,
2321
2290
scopedContext ,
2322
- abortController ,
2291
+ fogOfWar . active ,
2323
2292
flushSync ,
2324
2293
preventScrollReset ,
2325
2294
submission
@@ -2332,25 +2301,27 @@ export function createRouter(init: RouterInit): Router {
2332
2301
key : string ,
2333
2302
routeId : string ,
2334
2303
path : string ,
2335
- match : AgnosticDataRouteMatch ,
2336
2304
requestMatches : AgnosticDataRouteMatch [ ] ,
2337
2305
scopedContext : unstable_RouterContextProvider ,
2338
- abortController : AbortController ,
2306
+ isFogOfWar : boolean ,
2339
2307
flushSync : boolean ,
2340
2308
preventScrollReset : boolean ,
2341
2309
submission : Submission
2342
2310
) {
2343
2311
interruptActiveLoads ( ) ;
2344
2312
fetchLoadMatches . delete ( key ) ;
2345
2313
2346
- if ( ! match . route . action && ! match . route . lazy ) {
2347
- let error = getInternalRouterError ( 405 , {
2348
- method : submission . formMethod ,
2349
- pathname : path ,
2350
- routeId : routeId ,
2351
- } ) ;
2352
- setFetcherError ( key , routeId , error , { flushSync } ) ;
2353
- return ;
2314
+ function detectAndHandle405Error ( m : AgnosticDataRouteMatch ) {
2315
+ if ( ! m . route . action && ! m . route . lazy ) {
2316
+ let error = getInternalRouterError ( 405 , {
2317
+ method : submission . formMethod ,
2318
+ pathname : path ,
2319
+ routeId : routeId ,
2320
+ } ) ;
2321
+ setFetcherError ( key , routeId , error , { flushSync } ) ;
2322
+ return true ;
2323
+ }
2324
+ return false ;
2354
2325
}
2355
2326
2356
2327
// Put this fetcher into it's submitting state
@@ -2359,13 +2330,46 @@ export function createRouter(init: RouterInit): Router {
2359
2330
flushSync,
2360
2331
} ) ;
2361
2332
2333
+ let abortController = new AbortController ( ) ;
2362
2334
let fetchRequest = createClientSideRequest (
2363
2335
init . history ,
2364
2336
path ,
2365
2337
abortController . signal ,
2366
2338
submission
2367
2339
) ;
2368
2340
2341
+ if ( isFogOfWar ) {
2342
+ let discoverResult = await discoverRoutes (
2343
+ requestMatches ,
2344
+ path ,
2345
+ fetchRequest . signal ,
2346
+ key
2347
+ ) ;
2348
+
2349
+ if ( discoverResult . type === "aborted" ) {
2350
+ return ;
2351
+ } else if ( discoverResult . type === "error" ) {
2352
+ setFetcherError ( key , routeId , discoverResult . error , { flushSync } ) ;
2353
+ return ;
2354
+ } else if ( ! discoverResult . matches ) {
2355
+ setFetcherError (
2356
+ key ,
2357
+ routeId ,
2358
+ getInternalRouterError ( 404 , { pathname : path } ) ,
2359
+ { flushSync }
2360
+ ) ;
2361
+ return ;
2362
+ } else {
2363
+ requestMatches = discoverResult . matches ;
2364
+ }
2365
+ }
2366
+
2367
+ let match = getTargetMatch ( requestMatches , path ) ;
2368
+
2369
+ if ( detectAndHandle405Error ( match ) ) {
2370
+ return ;
2371
+ }
2372
+
2369
2373
// Call the action for the fetcher
2370
2374
fetchControllers . set ( key , abortController ) ;
2371
2375
@@ -2608,10 +2612,9 @@ export function createRouter(init: RouterInit): Router {
2608
2612
key : string ,
2609
2613
routeId : string ,
2610
2614
path : string ,
2611
- match : AgnosticDataRouteMatch ,
2612
2615
matches : AgnosticDataRouteMatch [ ] ,
2613
2616
scopedContext : unstable_RouterContextProvider ,
2614
- abortController : AbortController ,
2617
+ isFogOfWar : boolean ,
2615
2618
flushSync : boolean ,
2616
2619
preventScrollReset : boolean ,
2617
2620
submission ?: Submission
@@ -2626,12 +2629,41 @@ export function createRouter(init: RouterInit): Router {
2626
2629
{ flushSync }
2627
2630
) ;
2628
2631
2632
+ let abortController = new AbortController ( ) ;
2629
2633
let fetchRequest = createClientSideRequest (
2630
2634
init . history ,
2631
2635
path ,
2632
2636
abortController . signal
2633
2637
) ;
2634
2638
2639
+ if ( isFogOfWar ) {
2640
+ let discoverResult = await discoverRoutes (
2641
+ matches ,
2642
+ path ,
2643
+ fetchRequest . signal ,
2644
+ key
2645
+ ) ;
2646
+
2647
+ if ( discoverResult . type === "aborted" ) {
2648
+ return ;
2649
+ } else if ( discoverResult . type === "error" ) {
2650
+ setFetcherError ( key , routeId , discoverResult . error , { flushSync } ) ;
2651
+ return ;
2652
+ } else if ( ! discoverResult . matches ) {
2653
+ setFetcherError (
2654
+ key ,
2655
+ routeId ,
2656
+ getInternalRouterError ( 404 , { pathname : path } ) ,
2657
+ { flushSync }
2658
+ ) ;
2659
+ return ;
2660
+ } else {
2661
+ matches = discoverResult . matches ;
2662
+ }
2663
+ }
2664
+
2665
+ let match = getTargetMatch ( matches , path ) ;
2666
+
2635
2667
// Call the loader for this fetcher route match
2636
2668
fetchControllers . set ( key , abortController ) ;
2637
2669
@@ -3236,7 +3268,7 @@ export function createRouter(init: RouterInit): Router {
3236
3268
true
3237
3269
) ;
3238
3270
3239
- return { active : true , matches : fogMatches } ;
3271
+ return { active : true , matches : fogMatches || [ ] } ;
3240
3272
} else {
3241
3273
if ( Object . keys ( matches [ 0 ] . params ) . length > 0 ) {
3242
3274
// If we matched a dynamic param or a splat, it might only be because
0 commit comments