11<script setup lang="ts">
22import type { PackageFileTree } from ' #shared/types'
3+ import type { RouteLocationRaw } from ' vue-router'
34import { getFileIcon } from ' ~/utils/file-icons'
45import { formatBytes } from ' ~/utils/formatters'
56
67const props = defineProps <{
78 tree: PackageFileTree []
89 currentPath: string
910 baseUrl: string
11+ /** Base path segments for the code route (e.g., ['nuxt', 'v', '4.2.0']) */
12+ basePath: string []
1013}>()
1114
1215// Get the current directory's contents
@@ -36,6 +39,18 @@ const parentPath = computed(() => {
3639 if (parts .length <= 1 ) return ' '
3740 return parts .slice (0 , - 1 ).join (' /' )
3841})
42+
43+ // Build route object for a path
44+ function getCodeRoute(nodePath ? : string ): RouteLocationRaw {
45+ if (! nodePath ) {
46+ return { name: ' code' , params: { path: props .basePath as [string , ... string []] } }
47+ }
48+ const pathSegments = [... props .basePath , ... nodePath .split (' /' )]
49+ return {
50+ name: ' code' ,
51+ params: { path: pathSegments as [string , ... string []] },
52+ }
53+ }
3954 </script >
4055
4156<template >
@@ -61,7 +76,7 @@ const parentPath = computed(() => {
6176 >
6277 <td class =" py-2 px-4" >
6378 <NuxtLink
64- :to =" parentPath ? `${baseUrl}/${parentPath}` : baseUrl "
79+ :to =" getCodeRoute( parentPath || undefined) "
6580 class =" flex items-center gap-2 font-mono text-sm text-fg-muted hover:text-fg transition-colors"
6681 >
6782 <span class =" i-carbon:folder w-4 h-4 text-yellow-600" />
@@ -79,7 +94,7 @@ const parentPath = computed(() => {
7994 >
8095 <td class =" py-2 px-4" >
8196 <NuxtLink
82- :to =" `${baseUrl}/${ node.path}` "
97+ :to =" getCodeRoute( node.path) "
8398 class =" flex items-center gap-2 font-mono text-sm hover:text-fg transition-colors"
8499 :class =" node.type === 'directory' ? 'text-fg' : 'text-fg-muted'"
85100 >
0 commit comments