···42424343const packageName = computed(() => parsedRoute.value.packageName)
4444const version = computed(() => parsedRoute.value.version)
4545-const filePath = computed(() => parsedRoute.value.filePath)
4545+const filePathOrig = computed(() => parsedRoute.value.filePath)
4646+const filePath = computed(() => parsedRoute.value.filePath?.replace(/\/$/, ''))
46474748// Fetch package data for version list
4849const { data: pkg } = usePackage(packageName)
···6465// Determine what to show based on the current path
6566// Note: This needs fileTree to be loaded first
6667const currentNode = computed(() => {
6767- if (!fileTree.value?.tree || !filePath.value) return null
6868+ if (!fileTree.value?.tree || !filePathOrig.value) return null
68696969- const parts = filePath.value.split('/')
7070+ // We use original file path to correctly handle trailing slashes for file tree navigation
7171+ // - /src/index.ts - correct file path
7272+ // - /src/index.ts/ - incorrect file path (but formally can exist as a directory)
7373+ // - /src/index and /src/index/ - correct directory paths
7474+ const parts = filePathOrig.value.split('/')
7075 let current: PackageFileTree[] | undefined = fileTree.value.tree
7176 let lastFound: PackageFileTree | null = null
7777+ const partsLength = parts.length
72787373- for (const part of parts) {
7979+ for (let i = 0; i < partsLength; i++) {
8080+ const part = parts[i]
8181+ const isLast = i === partsLength - 1
8282+ // If the previous part is a directory and the last one is empty (like /lib/) then return the previous directory
8383+ 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
7777- if (found.type === 'file') return found
8787+ if (found.type === 'file' && isLast) return found
7888 current = found.children
7989 }
8090