@@ -21,7 +21,7 @@ import { Breadcrumbs } from '@/components/ui/breadcrumbs';
2121import { getLandingEntries } from '@/lib/config' ;
2222import { getActiveContentDir } from '@/lib/navigation' ;
2323import { usePageContext } from '@/lib/page-context' ;
24- import type { Node } from 'fumadocs-core/page-tree' ;
24+ import type { Node , Root } from 'fumadocs-core/page-tree' ;
2525import type { ThemeLayoutProps } from '@/types' ;
2626import styles from './Layout.module.css' ;
2727import { OpenInAI } from './OpenInAI' ;
@@ -71,7 +71,12 @@ export function Layout({
7171 const isApiRoute = pathname === '/apis' || pathname . startsWith ( '/apis/' ) ;
7272 const isApiBase = ( basePath : string ) =>
7373 pathname === basePath || pathname . startsWith ( `${ basePath } /` ) ;
74- const { prev, next } = page ?? { prev : null , next : null } ;
74+ const docNav = page ?? { prev : null , next : null } ;
75+ const apiNav = useMemo ( ( ) => {
76+ if ( ! isApiRoute ) return { prev : null , next : null } ;
77+ return getApiPrevNext ( pathname , tree ) ;
78+ } , [ isApiRoute , pathname , tree ] ) ;
79+ const { prev, next } = isApiRoute ? apiNav : docNav ;
7580
7681 const contentEntries = getLandingEntries ( config , version . dir ) ;
7782 const activeContentDir = getActiveContentDir ( pathname , config ) ;
@@ -200,7 +205,7 @@ export function Layout({
200205 < ArrowRightIcon width = { 14 } height = { 14 } />
201206 </ IconButton >
202207 </ Flex >
203- { ! isApiRoute && < Breadcrumbs slug = { slug } tree = { tree } /> }
208+ < Breadcrumbs slug = { slug } tree = { tree } />
204209 </ Flex >
205210 < Flex align = 'center' gap = 'small' >
206211 { isApiRoute && < TestRequestButton /> }
@@ -390,3 +395,21 @@ function ViewDocsButton() {
390395 </ Button >
391396 ) ;
392397}
398+
399+ function getApiPrevNext ( pathname : string , tree : Root ) : { prev : { url : string ; title : string } | null ; next : { url : string ; title : string } | null } {
400+ const pages : { url : string ; title : string } [ ] = [ ] ;
401+ function collect ( node : Node ) {
402+ if ( node . type === 'page' ) {
403+ pages . push ( { url : node . url , title : node . name ?. toString ( ) ?? '' } ) ;
404+ } else if ( node . type === 'folder' ) {
405+ for ( const child of node . children ) collect ( child ) ;
406+ }
407+ }
408+ for ( const child of tree . children ) collect ( child ) ;
409+
410+ const idx = pages . findIndex ( p => p . url === pathname ) ;
411+ return {
412+ prev : idx > 0 ? pages [ idx - 1 ] : null ,
413+ next : idx >= 0 && idx < pages . length - 1 ? pages [ idx + 1 ] : null ,
414+ } ;
415+ }
0 commit comments