@@ -1146,8 +1146,8 @@ export class RouterCore<
1146
1146
const parentMatchId = parentMatch ?. id
1147
1147
1148
1148
const parentContext = ! parentMatchId
1149
- ? ( ( this . options . context as any ) ?? { } )
1150
- : ( parentMatch . context ?? this . options . context ?? { } )
1149
+ ? ( ( this . options . context as any ) ?? undefined )
1150
+ : ( parentMatch . context ?? this . options . context ?? undefined )
1151
1151
1152
1152
return parentContext
1153
1153
}
@@ -1169,12 +1169,12 @@ export class RouterCore<
1169
1169
] = ( ( ) => {
1170
1170
// Validate the search params and stabilize them
1171
1171
const parentSearch = parentMatch ?. search ?? next . search
1172
- const parentStrictSearch = parentMatch ?. _strictSearch ?? { }
1172
+ const parentStrictSearch = parentMatch ?. _strictSearch ?? undefined
1173
1173
1174
1174
try {
1175
1175
const strictSearch =
1176
1176
validateSearch ( route . options . validateSearch , { ...parentSearch } ) ??
1177
- { }
1177
+ undefined
1178
1178
1179
1179
return [
1180
1180
{
@@ -1284,7 +1284,7 @@ export class RouterCore<
1284
1284
isFetching : false ,
1285
1285
error : undefined ,
1286
1286
paramsError : parseErrors [ index ] ,
1287
- __routeContext : { } ,
1287
+ __routeContext : undefined ,
1288
1288
_nonReactive : {
1289
1289
loadPromise : createControlledPromise ( ) ,
1290
1290
} ,
@@ -1337,22 +1337,25 @@ export class RouterCore<
1337
1337
const parentContext = getParentContext ( parentMatch )
1338
1338
1339
1339
// Update the match's context
1340
- const contextFnContext : RouteContextOptions < any , any , any , any > = {
1341
- deps : match . loaderDeps ,
1342
- params : match . params ,
1343
- context : parentContext ,
1344
- location : next ,
1345
- navigate : ( opts : any ) =>
1346
- this . navigate ( { ...opts , _fromLocation : next } ) ,
1347
- buildLocation : this . buildLocation ,
1348
- cause : match . cause ,
1349
- abortController : match . abortController ,
1350
- preload : ! ! match . preload ,
1351
- matches,
1352
- }
1353
1340
1354
- // Get the route context
1355
- match . __routeContext = route . options . context ?.( contextFnContext ) ?? { }
1341
+ if ( route . options . context ) {
1342
+ const contextFnContext : RouteContextOptions < any , any , any , any > = {
1343
+ deps : match . loaderDeps ,
1344
+ params : match . params ,
1345
+ context : parentContext ?? { } ,
1346
+ location : next ,
1347
+ navigate : ( opts : any ) =>
1348
+ this . navigate ( { ...opts , _fromLocation : next } ) ,
1349
+ buildLocation : this . buildLocation ,
1350
+ cause : match . cause ,
1351
+ abortController : match . abortController ,
1352
+ preload : ! ! match . preload ,
1353
+ matches,
1354
+ }
1355
+ // Get the route context
1356
+ match . __routeContext =
1357
+ route . options . context ( contextFnContext ) ?? undefined
1358
+ }
1356
1359
1357
1360
match . context = {
1358
1361
...parentContext ,
@@ -1486,13 +1489,9 @@ export class RouterCore<
1486
1489
parseCache : this . parsePathnameCache ,
1487
1490
} ) . interpolatedPath
1488
1491
1489
- const destRoutes = this . matchRoutes (
1490
- interpolatedNextTo ,
1491
- { } ,
1492
- {
1493
- _buildLocation : true ,
1494
- } ,
1495
- ) . map ( ( d ) => this . looseRoutesById [ d . routeId ] ! )
1492
+ const destRoutes = this . matchRoutes ( interpolatedNextTo , undefined , {
1493
+ _buildLocation : true ,
1494
+ } ) . map ( ( d ) => this . looseRoutesById [ d . routeId ] ! )
1496
1495
1497
1496
// If there are any params, we need to stringify them
1498
1497
if ( Object . keys ( nextParams ) . length > 0 ) {
@@ -2378,7 +2377,7 @@ export class RouterCore<
2378
2377
const abortController = new AbortController ( )
2379
2378
2380
2379
const parentMatchContext =
2381
- parentMatch ?. context ?? this . options . context ?? { }
2380
+ parentMatch ?. context ?? this . options . context ?? undefined
2382
2381
2383
2382
updateMatch ( matchId , ( prev ) => ( {
2384
2383
...prev ,
@@ -2787,7 +2786,7 @@ export class RouterCore<
2787
2786
invalid : true ,
2788
2787
...( opts ?. forcePending || d . status === 'error'
2789
2788
? ( { status : 'pending' , error : undefined } as const )
2790
- : { } ) ,
2789
+ : undefined ) ,
2791
2790
}
2792
2791
}
2793
2792
return d
@@ -3558,7 +3557,8 @@ function applySearchMiddleware({
3558
3557
try {
3559
3558
const validatedSearch = {
3560
3559
...result ,
3561
- ...( validateSearch ( route . options . validateSearch , result ) ?? { } ) ,
3560
+ ...( validateSearch ( route . options . validateSearch , result ) ??
3561
+ undefined ) ,
3562
3562
}
3563
3563
return validatedSearch
3564
3564
} catch {
0 commit comments