@@ -42,7 +42,8 @@ const parsedRoute = computed(() => {
4242
4343const packageName = computed (() => parsedRoute .value .packageName )
4444const version = computed (() => parsedRoute .value .version )
45- const filePath = computed (() => parsedRoute .value .filePath )
45+ const filePathOrig = computed (() => parsedRoute .value .filePath )
46+ const filePath = computed (() => parsedRoute .value .filePath ?.replace (/ \/ $ / , ' ' ))
4647
4748// Fetch package data for version list
4849const { data : pkg } = usePackage (packageName )
@@ -64,17 +65,26 @@ const { data: fileTree, status: treeStatus } = useFetch<PackageFileTreeResponse>
6465// Determine what to show based on the current path
6566// Note: This needs fileTree to be loaded first
6667const currentNode = computed (() => {
67- if (! fileTree .value ?.tree || ! filePath .value ) return null
68+ if (! fileTree .value ?.tree || ! filePathOrig .value ) return null
6869
69- const parts = filePath .value .split (' /' )
70+ // We use original file path to correctly handle trailing slashes for file tree navigation
71+ // - /src/index.ts - correct file path
72+ // - /src/index.ts/ - incorrect file path (but formally can exist as a directory)
73+ // - /src/index and /src/index/ - correct directory paths
74+ const parts = filePathOrig .value .split (' /' )
7075 let current: PackageFileTree [] | undefined = fileTree .value .tree
7176 let lastFound: PackageFileTree | null = null
77+ const partsLength = parts .length
7278
73- for (const part of parts ) {
79+ for (let i = 0 ; i < partsLength ; i ++ ) {
80+ const part = parts [i ]
81+ const isLast = i === partsLength - 1
82+ // If the previous part is a directory and the last one is empty (like /lib/) then return the previous directory
83+ if (! part && isLast && lastFound ?.type === ' directory' ) return lastFound
7484 const found: PackageFileTree | undefined = current ?.find (n => n .name === part )
7585 if (! found ) return null
7686 lastFound = found
77- if (found .type === ' file' ) return found
87+ if (found .type === ' file' && isLast ) return found
7888 current = found .children
7989 }
8090
0 commit comments