Skip to content

getAncestorNodes

The nodes above a slug, from the root down.

View Markdown

Returns the ancestors of a node, from the root down to its parent. The node itself is not included.

src/app/docs/[...slug]/page.tsx
const ancestors = await docsTree.getAncestorNodes(
  "guides/mutations/optimistic",
);
// TreeNodes for "guides" and "guides/mutations"

Signature

@qino/cms
tree.getAncestorNodes(slug: Slug): Promise<Array<TreeNode>>;

Parameters

NameTypeRequiredDescription
slugstringyesSlug of the current node

Returns

Promise<Array<TreeNode>>. Empty for a root-level node.

Throws

  • Tree entry "<slug>" not found in tree "<directory>".
  • The walk errors listed on getTree.

Example

src/app/docs/[...slug]/page.tsx
const ancestors = await docsTree.getAncestorNodes(slug);

<nav aria-label="Breadcrumb">
  {ancestors.map((node) => (
    <a key={node.slug} href={`/docs/${node.slug}`}>
      {node.title}
    </a>
  ))}
</nav>;