@@ -20,17 +20,26 @@ const parsedRoute = computed(() => {
2020 return {
2121 packageName: segments .join (' /' ),
2222 version: null as string | null ,
23+ entrypoint: null as string | null ,
2324 }
2425 }
2526
27+ // Version is the segment right after "v"
28+ const version = segments [vIndex + 1 ]!
29+ // Everything after the version is the entrypoint path (e.g., "router.js")
30+ const entrypointSegments = segments .slice (vIndex + 2 )
31+ const entrypoint = entrypointSegments .length > 0 ? entrypointSegments .join (' /' ) : null
32+
2633 return {
2734 packageName: segments .slice (0 , vIndex ).join (' /' ),
28- version: segments .slice (vIndex + 1 ).join (' /' ),
35+ version ,
36+ entrypoint ,
2937 }
3038})
3139
3240const packageName = computed (() => parsedRoute .value .packageName )
3341const requestedVersion = computed (() => parsedRoute .value .version )
42+ const entrypoint = computed (() => parsedRoute .value .entrypoint )
3443
3544// Validate package name on server-side for early error detection
3645if (import .meta .server && packageName .value ) {
@@ -90,7 +99,8 @@ useCommandPalettePackageCommands(commandPalettePackageContext)
9099
91100const docsUrl = computed (() => {
92101 if (! packageName .value || ! resolvedVersion .value ) return null
93- return ` /api/registry/docs/${packageName .value }/v/${resolvedVersion .value } `
102+ const base = ` /api/registry/docs/${packageName .value }/v/${resolvedVersion .value } `
103+ return entrypoint .value ? ` ${base }/${entrypoint .value } ` : base
94104})
95105
96106const shouldFetch = computed (() => !! docsUrl .value )
@@ -119,9 +129,10 @@ const latestVersionDetailed = computed(() => {
119129 return pkg .value .versions [latestTag ] ?? null
120130})
121131
122- const versionUrlPattern = computed (
123- () => ` /package-docs/${pkg .value ?.name || packageName .value }/v/{version} ` ,
124- )
132+ const versionUrlPattern = computed (() => {
133+ const base = ` /package-docs/${pkg .value ?.name || packageName .value }/v/{version} `
134+ return entrypoint .value ? ` ${base }/${entrypoint .value } ` : base
135+ })
125136
126137useCommandPaletteVersionCommands (commandPalettePackageContext , versionUrlPattern )
127138
@@ -159,6 +170,27 @@ const stickyStyle = computed(() => {
159170 ' --combined-header-height' : ` ${56 + (packageHeaderHeight .value || 44 )}px ` ,
160171 }
161172})
173+
174+ // Multi-entrypoint support
175+ const entrypoints = computed (() => docsData .value ?.entrypoints ?? null )
176+ const currentEntrypoint = computed (() => docsData .value ?.entrypoint ?? entrypoint .value ?? ' ' )
177+
178+ // Redirect to first entrypoint for multi-entrypoint packages
179+ watch (docsData , data => {
180+ if (data ?.entrypoints ?.length && ! entrypoint .value && resolvedVersion .value ) {
181+ const firstEntrypoint = data .entrypoints [0 ]!
182+ const pathSegments = [
183+ ... packageName .value .split (' /' ),
184+ ' v' ,
185+ resolvedVersion .value ,
186+ ... firstEntrypoint .split (' /' ),
187+ ]
188+ router .replace ({
189+ name: ' docs' ,
190+ params: { path: pathSegments as [string , ... string []] },
191+ })
192+ }
193+ })
162194 </script >
163195
164196<template >
@@ -172,6 +204,18 @@ const stickyStyle = computed(() => {
172204 page =" docs"
173205 />
174206
207+ <div
208+ v-if =" entrypoints && currentEntrypoint && resolvedVersion"
209+ class =" container py-2 border-b border-border"
210+ >
211+ <EntrypointSelector
212+ :package-name =" packageName"
213+ :version =" resolvedVersion"
214+ :current-entrypoint =" currentEntrypoint"
215+ :entrypoints =" entrypoints"
216+ />
217+ </div >
218+
175219 <div class =" flex" dir =" ltr" >
176220 <!-- Sidebar TOC -->
177221 <aside
0 commit comments