We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Directory Component

The Directory component creates structured, hierarchical navigation with collapsible sections. Perfect for documentation sites, file explorers, and nested navigation menus. Inspired by the Astro Starlight navigation component.

  • Check Circle

    Hierarchical Display: Visualize complex content structures

  • Check Circle

    Collapsible Sections: Toggle visibility of nested items

  • Check Circle

    Active Item Tracking: Automatically highlights current selection

  • Check Circle

    Smooth Scrolling: Auto-scrolls to active items

  • Check Circle

    Badge Support: Add visual indicators to items

<Directory
directory={[{
label: 'Getting Started',
items: [
{ label: 'Installation', href: '/docs/installation' },
{ label: 'Configuration', href: '/docs/configuration' },
],
}]}
currentDocSlug="installation"
collapsable={true}
/>

Limit the nesting depth of your directory structure:

<Directory directory={directoryData} maxDepth={3} Only show 3 levels of nesting />

Below is an example of how to utilize the Directory component with the Astro content collections. You can see the example on the left side of the screen now, we use this component for our documentation navigation.

---
import { type CollectionEntry } from 'astro:content';
import Directory from '@/components/NST-components/UI/directory/Directory.astro';
import { getCollection } from 'astro:content';
export interface Props {
post?: CollectionEntry<'docs'>;
}
const { post } = Astro.props;
const { slug } = post || {};
const directory = await getCollection('docs');
---
<Directory
collapsable
currentDocSlug={slug || ''}
baseUrl="/docs/"
{directory}
/>
import { badgeStyleKeys } from '@/components/NST-components/UI/badge/styling';
import { defineCollection, z } from 'astro:content';
const docs = defineCollection({
type: 'content',
schema: () =>
z.object({
sidebar: z
.object({
label: z.string(),
dropDownLabel: z.string().optional(),
order: z.number().optional(),
badge: z
.object({
text: z.string(),
variant: z.enum(badgeStyleKeys),
})
.optional(),
})
.optional(),
}),
});
export const collections = { docs };

Set the base URL to the root of your content collection. This is used to generate the correct URLs for the directory items. If all your content collection starts at the path /docs/, you can set the base URL to /docs/.

Directory Component Props Extends <div> HTMLElement
Prop Type Default Description
baseUrl string Base URL for the directory
collapsable boolean false Enable collapsible sections
currentDocSlug string Slug of the current active document
defaultCollapsed boolean true Initial collapsed state of sections
directory DirectoryItem[] Array of directory items and their structure
maxDepth number 9 Maximum nesting depth to display
interface DirectoryItem {
label: string;
href?: string;
items?: any[];
badge?: {
variant: BadgeStyleKeys;
text: string;
};
dropDownLabel?: string;
dropDownBadge?: {
variant: BadgeStyleKeys;
text: string;
};
collapsed?: boolean;
}
  1. Structure Organization

    • Keep nesting depth reasonable (3-4 levels max)
    • Use clear, descriptive labels
    • Group related items logically
    • Consider alphabetical ordering
  2. Visual Clarity

    • Use badges sparingly
    • Maintain consistent spacing
    • Ensure sufficient contrast
    • Consider mobile viewports
Documentation navigation
File system explorers
Product categories
Organization charts
Content management systems

Limited Time Launch Sale

Build intuitive navigation structures with our Directory component. Get the AstroJS starter template now and create organized, accessible content hierarchies.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes