@@ -52,6 +52,7 @@ import type {
5252 RenderReturnNode ,
5353 RuntimeBrickConfWithSymbols ,
5454 RuntimeContext ,
55+ RouteNode ,
5556} from "./interfaces.js" ;
5657import {
5758 getTagNameOfCustomTemplate ,
@@ -99,7 +100,7 @@ export async function renderRoutes(
99100 routes : RouteConf [ ] ,
100101 _runtimeContext : RuntimeContext ,
101102 rendererContext : RendererContext ,
102- parentRoutes : RouteConf [ ] ,
103+ parentRoutes : RouteNode [ ] ,
103104 menuRequestReturnNode : MenuRequestNode ,
104105 slotId ?: string ,
105106 isIncremental ?: boolean ,
@@ -131,7 +132,7 @@ export async function renderRoutes(
131132 if ( isIncremental ) {
132133 runtimeContext . ctxStore . disposeDataInRoutes ( routes ) ;
133134 }
134- const routePath = parentRoutes . concat ( route ) ;
135+ const routePath = parentRoutes . concat ( { route, routes } ) ;
135136 runtimeContext . ctxStore . define (
136137 route . context ,
137138 runtimeContext ,
@@ -246,7 +247,7 @@ export async function renderBricks(
246247 bricks : BrickConf [ ] ,
247248 runtimeContext : RuntimeContext ,
248249 rendererContext : RendererContext ,
249- parentRoutes : RouteConf [ ] ,
250+ parentRoutes : RouteNode [ ] ,
250251 menuRequestReturnNode : MenuRequestNode ,
251252 slotId ?: string ,
252253 tplStack ?: Map < string , number > ,
@@ -283,7 +284,7 @@ export async function renderBrick(
283284 brickConf : RuntimeBrickConfWithSymbols ,
284285 _runtimeContext : RuntimeContext ,
285286 rendererContext : RendererContext ,
286- parentRoutes : RouteConf [ ] ,
287+ parentRoutes : RouteNode [ ] ,
287288 menuRequestReturnNode : MenuRequestNode ,
288289 slotId ?: string ,
289290 tplStack = new Map < string , number > ( ) ,
@@ -320,7 +321,7 @@ async function legacyRenderBrick(
320321 brickConf : RuntimeBrickConfWithSymbols ,
321322 _runtimeContext : RuntimeContext ,
322323 rendererContext : RendererContext ,
323- parentRoutes : RouteConf [ ] ,
324+ parentRoutes : RouteNode [ ] ,
324325 menuRequestReturnNode : MenuRequestNode ,
325326 slotId : string | undefined ,
326327 tplStack : Map < string , number > ,
@@ -912,30 +913,34 @@ async function legacyRenderBrick(
912913 } ;
913914 lastOutput . node = abstractNode ;
914915
915- const parentRoute = parentRoutes [ parentRoutes . length - 1 ] as
916- | RouteConfOfBricks
917- | undefined ;
918- if ( parentRoute ?. incrementalSubRoutes ) {
916+ const { route : parentRoute } = parentRoutes [ parentRoutes . length - 1 ] ;
917+ if ( ( parentRoute as RouteConfOfBricks ) ?. incrementalSubRoutes ) {
919918 routeSlotFromIndexToSlotId . set ( index , childSlotId ) ;
920919 rendererContext . performIncrementalRender (
921920 slotConf ,
922- parentRoutes ,
921+ parentRoutes . map ( ( { route } ) => route ) ,
923922 async ( location , prevLocation ) => {
924923 const { homepage } = childRuntimeContext . app ;
925924 const { pathname } = location ;
926925 // Ignore if any one of homepage and parent routes not matched.
927926 if (
928927 ! matchHomepage ( homepage , pathname ) ||
929- ! parentRoutes . every ( ( route ) => {
930- let prevMatch : MatchResult | null ;
931- let newMatch : MatchResult | null ;
928+ ! parentRoutes . every ( ( { route, routes } ) => {
929+ let prevMatch : MatchResult | null = null ;
930+ let newMatch : MatchResult | null = null ;
932931 return (
933- ( prevMatch = matchRoute (
932+ ( prevMatch = matchTargetRoute (
934933 route ,
934+ routes ,
935935 homepage ,
936936 prevLocation . pathname
937937 ) ) &&
938- ( newMatch = matchRoute ( route , homepage , pathname ) ) &&
938+ ( newMatch = matchTargetRoute (
939+ route ,
940+ routes ,
941+ homepage ,
942+ pathname
943+ ) ) &&
939944 ( route !== parentRoute ||
940945 isRouteParamsEqual ( prevMatch . params , newMatch . params ) )
941946 ) ;
@@ -1124,7 +1129,7 @@ async function renderForEach(
11241129 bricks : BrickConf [ ] ,
11251130 runtimeContext : RuntimeContext ,
11261131 rendererContext : RendererContext ,
1127- parentRoutes : RouteConf [ ] ,
1132+ parentRoutes : RouteNode [ ] ,
11281133 menuRequestReturnNode : MenuRequestNode ,
11291134 slotId : string | undefined ,
11301135 tplStack : Map < string , number > ,
@@ -1369,3 +1374,23 @@ function isRouteParamsEqual(
13691374function isRouteConf ( child : BrickConf | RouteConf ) : child is RouteConf {
13701375 return ! ! ( child as RouteConf ) . path && ! ( child as BrickConf ) . brick ;
13711376}
1377+
1378+ /**
1379+ * Find the first matched route among siblings.
1380+ *
1381+ * Return the match result only if it matches the target route.
1382+ */
1383+ function matchTargetRoute (
1384+ route : RouteConf ,
1385+ routes : RouteConf [ ] ,
1386+ homepage : string ,
1387+ pathname : string
1388+ ) {
1389+ for ( const sibling of routes ) {
1390+ const match = matchRoute ( sibling , homepage , pathname ) ;
1391+ if ( match ) {
1392+ return sibling === route ? match : null ;
1393+ }
1394+ }
1395+ return null ;
1396+ }
0 commit comments