Skip to content

Commit db0a9d8

Browse files
committed
refactor: improve child route key handling in Outlet component
1 parent b3e32c0 commit db0a9d8

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎packages/solid-router/src/Match.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,19 @@ export const Outlet = () => {
469469
return router.stores.matchStores.get(id)?.get().status
470470
})
471471

472-
// Only show not-found if we're not in a redirected state
473472
const shouldShowNotFound = () =>
474473
childMatchStatus() !== 'redirected' && parentGlobalNotFound()
475474

475+
const childRouteKey = Solid.createMemo(() => {
476+
if (shouldShowNotFound()) return undefined
477+
const cid = childMatchId()
478+
if (!cid) return undefined
479+
return router.stores.matchStores.get(cid)?.routeId ?? cid
480+
})
481+
476482
return (
477483
<Solid.Show
478-
when={!shouldShowNotFound() && childMatchId()}
484+
when={childRouteKey()}
479485
keyed
480486
fallback={
481487
<Solid.Show when={shouldShowNotFound() && route()}>
@@ -485,18 +491,18 @@ export const Outlet = () => {
485491
</Solid.Show>
486492
}
487493
>
488-
{(currentMatchId: string) => {
494+
{(_routeKey: string) => {
489495
return (
490496
<Solid.Show
491497
when={routeId() === rootRouteId}
492-
fallback={<Match matchId={currentMatchId} />}
498+
fallback={<Match matchId={childMatchId()!} />}
493499
>
494500
<Solid.Suspense
495501
fallback={
496502
<Dynamic component={router.options.defaultPendingComponent} />
497503
}
498504
>
499-
<Match matchId={currentMatchId} />
505+
<Match matchId={childMatchId()!} />
500506
</Solid.Suspense>
501507
</Solid.Show>
502508
)

0 commit comments

Comments
 (0)