Overview
The Page Tree API provides types and utilities for working with hierarchical navigation structures in Fumadocs. Page trees represent the sidebar navigation of your documentation.Types
Root
The root of a page tree.Unique identifier for the root node
Display name of the root
Child nodes of the root
Alternative page tree that won’t be displayed unless explicitly opened
Node
A node in the page tree can be an Item, Separator, or Folder.Item
Represents a page in the navigation.Node type discriminator
Display name of the page
Page URL
Whether the link should be treated as external (uses HTML
<a> tag)Page description
Icon element for the page
Folder
Represents a collapsible folder in the navigation.Node type discriminator
Display name of the folder
Whether this folder is a root folder (affects navigation behavior)
Whether the folder should be open by default
Whether the folder can be collapsed
Index page for the folder
Child nodes within the folder
Separator
A visual separator in the navigation.Node type discriminator
Optional label for the separator
Utility Functions
flattenTree()
Flatten a page tree into an array of page nodes.Array of page tree nodes to flatten
Flattened array of page items
findNeighbour()
Get the previous and next pages for navigation.The page tree to search
URL of the current page
Whether to treat root folders as separate navigation groups
Object containing:
previous: Previous page in navigation ordernext: Next page in navigation order
findPath()
Find the path to a node that matches a condition.Array of nodes to search
Function to match the target node
Whether to include separators in the path
Array of nodes from root to target, or null if not found
findParent()
Find the parent of a page by URL.Starting point for the search
URL of the page to find the parent of
The parent node, or undefined if not found
findSiblings()
Get sibling nodes that share the same parent.Page tree or trees (for i18n)
URL of the reference page
Array of sibling nodes (excluding the target page)
getPageTreePeers()
Get sibling pages (excludes folders and separators).Page tree or trees (for i18n)
URL of the reference page
Array of sibling page items only
getPageTreeRoots()
Get all root folders from a page tree.Page tree to extract roots from
Array of root-level folders
visit()
Perform a depth-first traversal of the page tree.Starting node for traversal
Callback function for each node. Can return:
'skip': Skip children of current node'break': Stop traversal- Modified node: Replace current node
void: Continue traversal
The transformed tree