@@ -393,10 +393,7 @@ int depth
393393 )
394394 {
395395 // tocRef.Path is now the FULL path (e.g., "guides/api" or "setup/advanced") after LoadAndResolve
396- // Extract just the last segment (relative part) for the URL path prefix
397396 var fullTocPath = tocRef . Path ;
398- var lastSlashIndex = fullTocPath . LastIndexOf ( '/' ) ;
399- var relativeTocPath = lastSlashIndex >= 0 ? fullTocPath [ ( lastSlashIndex + 1 ) ..] : fullTocPath ;
400397
401398 var tocDirectory = context . ReadFileSystem . DirectoryInfo . New (
402399 context . ReadFileSystem . Path . Combine ( context . DocumentationSourceDirectory . FullName , fullTocPath )
@@ -405,9 +402,10 @@ int depth
405402 // TODO: Add validation for TOCs with children in parent YAML
406403 // This is a known limitation - TOCs should not have children defined in parent YAML
407404
408- // Create a scoped path prefix for this TOC
409- var parentPrefix = homeProvider . PathPrefix . TrimEnd ( '/' ) ;
410- var scopedPathPrefix = string . IsNullOrEmpty ( parentPrefix ) ? $ "/{ relativeTocPath } " : $ "{ parentPrefix } /{ relativeTocPath } ";
405+ // According to url-building.md line 19-21: "We are not actually changing the PathPrefix,
406+ // we create the scope to be able to rehome during Assembler builds."
407+ // So TOC uses the SAME PathPrefix as its parent - it only creates a scope for rehoming
408+ var scopedPathPrefix = homeProvider . PathPrefix ;
411409
412410 // Create the TOC navigation with empty children initially
413411 // We use null parent temporarily - we'll set it properly at the end using the public setter
@@ -425,20 +423,25 @@ int depth
425423 NavigationIndex = index
426424 } ;
427425
428- // Convert children - pass tocNavigation as parent and as HomeProvider (TOC creates new scope)
426+ // Create a scoped HomeProvider for TOC children
427+ // According to url-building.md: "In isolated builds the NavigationRoot is always the DocumentationSetNavigation"
428+ // So we use the parent's NavigationRoot, not the TOC itself
429+ var tocHomeProvider = new NavigationHomeProvider ( scopedPathPrefix , homeProvider . NavigationRoot ) ;
430+
431+ // Convert children - pass tocNavigation as parent and tocHomeProvider as HomeProvider (TOC creates new scope)
429432 var children = new List < INavigationItem > ( ) ;
430433 var childIndex = 0 ;
431434
432435 // LoadAndResolve has already resolved children from the toc.yml file and prepended full paths.
433- // Children have full paths (e.g., "guides/api/reference.md"), so they should use tocNavigation as their HomeProvider
436+ // Children have full paths (e.g., "guides/api/reference.md"), so they should use the TOC's scoped HomeProvider
434437 foreach ( var child in tocRef . Children )
435438 {
436439 var childNav = ConvertToNavigationItem (
437440 child ,
438441 childIndex ++ ,
439442 context ,
440443 tocNavigation ,
441- tocNavigation , // TOC implements INavigationHomeProvider
444+ tocHomeProvider , // Use the scoped HomeProvider with correct NavigationRoot
442445 depth + 1
443446 ) ;
444447
@@ -476,14 +479,11 @@ int depth
476479 NavigationIndex = index
477480 } ;
478481
479- // Update children to point to the final TOC navigation
480- // This includes both Parent and HomeProvider (via INavigationHomeAccessor)
482+ // Update children's Parent to point to the final TOC navigation
483+ // Note: We don't update HomeProvider here because children already have the correct tocHomeProvider
484+ // which provides the scoped PathPrefix and correct NavigationRoot
481485 foreach ( var child in children )
482- {
483486 child . Parent = finalTocNavigation ;
484- if ( child is INavigationHomeAccessor accessor )
485- accessor . HomeProvider = finalTocNavigation ; // TOC implements INavigationHomeProvider
486- }
487487
488488 return finalTocNavigation ;
489489 }
0 commit comments