# Navigation

Organize the sidebar and navbar.

The sidebar lists the pages in `content/`, with a group for each folder. The navbar holds the site title and links.

## Sidebar [#sidebar]

The sidebar shows each page under the `title` in its [frontmatter](/markdown#frontmatter), and each folder as a group that opens on click. In a folder, `index.md` comes first, then the pages, then the subfolders, each in alphabetical order:

```files
content
├── index.md
├── getting-started.md
└── guide
    ├── index.md
    ├── install.md
    └── configure.md
```

`vuesho dev` updates the sidebar as you add, move or rename files, and each page's URL follows its [file path](/routing).

### Folders [#folders]

A `meta.json` in a folder sets the folder's title, its [icon](#icons) and the order of its pages:

```json title="content/guide/meta.json"
{
  "title": "Guide",
  "defaultOpen": true,
  "pages": ["install", "configure", "..."]
}
```

### MetaData

| Prop            | Type                                    | Description                                                                    |
| --------------- | --------------------------------------- | ------------------------------------------------------------------------------ |
| `title?`        | `string \| undefined`                   | The folder's title in the page tree.                                           |
| `description?`  | `string \| undefined`                   | A short description of the folder.                                             |
| `icon?`         | `string \| Component \| undefined`      | An icon name or component shown next to the folder title.                      |
| `root?`         | `string \| boolean \| undefined`        | A root folder is a sidebar tab. A string names its kind.                       |
| `pages?`        | `string[] \| undefined`                 | The order, separators, links and exclusions for the folder's items.            |
| `pagesIndex?`   | `string \| undefined`                   | The folder's index page, by its file name in the folder, as Fumadocs reads it. |
| `defaultOpen?`  | `boolean \| undefined`                  | Whether the folder starts expanded in the sidebar.                             |
| `collapsible?`  | `boolean \| undefined`                  | Whether the folder can collapse in the sidebar.                                |
| `staticParams?` | `Record<string, string>[] \| undefined` | The folder params of a dynamic folder.                                         |

The folder's sidebar item links to its `index.md`, and shows the `title` from `meta.json`, or the index page's title when `meta.json` has none. When `pages` lists `index`, the page has its own item instead.

A meta file can also be YAML, or a `meta.ts` module that runs when the site builds, for example to set [data per param value](/routing#data-per-value):

```json tab="meta.json"
{
  "title": "Guide",
  "pages": ["install", "configure", "..."]
}
```

```yaml tab="meta.yaml"
title: Guide
pages:
  - install
  - configure
  - "..."
```

```ts tab="meta.ts"
export default {
  title: "Guide",
  pages: ["install", "configure", "..."],
};
```

### Page Order [#page-order]

`pages` lists the pages and subfolders in order, by file name without `.md`. The list can also hold separators and links:

```yaml title="content/meta.yaml"
pages:
  # The page `index.md`. The root has no folder item that opens it, so list it here
  - index
  # The page `guide.md`, or the folder `guide/`.
  - guide
  # A separator titled "Reference". Write `---[Book]Reference---` to add an icon
  - ---Reference---
  # The pages of the folder `reference/`, in place of the folder.
  - ...reference
  # A link. Write `[Star][GitHub](https://...)` to add an icon
  - "[GitHub](https://github.com/acme/docs)"
  # An external link, with an external-link icon. It opens in a new tab
  - "external:[Discord](https://discord.gg/acme)"
  # The other pages, then folders, in alphabetical order. Use `z...a` for reverse order
  - "..."
  # Leaves `changelog` out of `...`.
  - "!changelog"
```

### Hidden Pages [#hidden-pages]

A page missing from `pages` is hidden from the sidebar, but keeps its URL. With `"..."` in the list, put `!` before a name to hide that page:

```json title="content/meta.json"
{
  "pages": ["index", "guide", "...", "!changelog"]
}
```

### Drafts [#drafts]

A page with `draft: true` in its frontmatter shows in `vuesho dev`, but the build leaves out the page, its sidebar item and its search entry:

```md title="content/next.md"
---
title: Next Release
draft: true
---
```

A link to a draft fails the build's [link validation](/markdown#link-validation).

## Root Folders [#root-folders]

A folder with `"root": true` is a separate section. The sidebar shows only the current section's pages, and a switch at the top of the sidebar opens the other sections:

```files
content
├── index.md
├── guide
│   ├── meta.json
│   └── install.md
└── api
    ├── meta.json
    └── reference.md
```

```json title="content/guide/meta.json"
{
  "title": "Guide",
  "description": "Learn the basics",
  "root": true
}
```

A page outside every root folder, like `content/index.md`, shows the whole sidebar.

### Versions [#versions]

Set `root` to a string, like `"version"`, to put the folders with the same string in a separate switch, such as a version switch:

```files
content
├── v1
│   ├── meta.json
│   └── guide.md
└── v2
    ├── meta.json
    └── guide.md
```

```json tab="content/v1/meta.json"
{
  "title": "v1",
  "root": "version"
}
```

```json tab="content/v2/meta.json"
{
  "title": "v2",
  "root": "version"
}
```

On `/v1/guide`, picking `v2` opens `/v2/guide`. When `/v2/guide` doesn't exist, it opens `v2`'s first page. A version folder can also hold sections with `"root": true`.

<Callout title="Switches in Layouts">
Only the `docs` and `notebook` [layouts](/layouts) show a switch for each string of `root`. The other layouts show only the folders with `"root": true`.
</Callout>

## Icons [#icons]

A page or a folder shows an icon beside its name in the sidebar. Import the icon from an icon library, like [Lucide](https://lucide.dev/icons), and set it as `icon` in code, so the site loads only the icons it uses:

```ts tab="content/guide/meta.ts"
import { BookOpen } from "@lucide/vue";

export default {
  title: "Guide",
  icon: BookOpen,
};
```

```md tab="content/guide/install.md"
---
title: Install
---

<script>
import { Rocket } from "@lucide/vue";

export const frontmatter = { icon: Rocket };
</script>
```

Any Vue component works, from any library.

### Icon Names [#icon-names]

`icon` in a page's frontmatter or in a `meta.json` can also be the name of a Lucide icon:

```md title="content/getting-started.md"
---
title: Getting Started
icon: Rocket
---
```

`lucideIconsPlugin()` renders the names as Lucide icons. Install `@lucide/vue` and add the plugin:

```npm
npm i @lucide/vue
```

```ts title="vuesho.config.ts"
import { createSite, recommendedPreset } from "vuesho/config";
import { defineDocs } from "vuesho/content";
import { lucideIconsPlugin } from "vuesho/lucide-icons"; // [!code ++]

const docs = defineDocs();

export default createSite(docs.toSource()).plugins(
  recommendedPreset(),
  // `defaultIcon` is the icon of a page or a folder without one.
  lucideIconsPlugin({ defaultIcon: "File" }), // [!code ++]
);
```

A name that Lucide doesn't have shows no icon, and `vuesho dev` logs a warning. The server keeps every Lucide icon to look the names up, so a site that doesn't use names can leave the plugin out.

### Custom Names [#custom-names]

Without the plugin, set `icon` in `createSite()` to a function that returns the icon for a name: a component, or text like an emoji:

```ts title="vuesho.config.ts"
import { BookOpen, Rocket } from "@lucide/vue";
import { createSite, recommendedPreset } from "vuesho/config";
import { defineDocs } from "vuesho/content";

const docs = defineDocs();
const icons = { BookOpen, Rocket };

export default createSite(docs.toSource(), {
  // A name of `icons` is its component, and any other name is shown as text.
  icon: (name) => (name === undefined ? undefined : (icons[name as keyof typeof icons] ?? name)),
}).plugins(recommendedPreset());
```

```md title="content/index.md"
---
title: Introduction
icon: 🚀
---
```

## Status Badges [#status-badges]

`statusBadgesPlugin()` shows a badge next to a page in the sidebar, from the `status` field in its frontmatter:

```md title="content/search.md"
---
title: Search
status: new
---
```

### Add the Plugin [#add-the-plugin-step]

```ts title="vuesho.config.ts"
import { statusBadgesPlugin } from "vuesho/status-badges"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset(),
  statusBadgesPlugin(), // [!code ++]
);
```

### Style the Badges [#style-the-badges-step]

A badge is a `<span data-status="...">` without styles. Style it in [your stylesheet](/styling):

```css title="src/theme.css"
@import "vuesho/style/neutral.css";

[data-status] {
  margin-inline-start: auto;
  border-radius: 9999px;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  background-color: var(--color-fd-primary);
  color: var(--color-fd-primary-foreground);
}

[data-status="deprecated"] {
  background-color: var(--color-fd-muted);
  color: var(--color-fd-muted-foreground);
}
```

To render a custom badge for each status, as text or a VNode, use `renderBadge`:

```ts title="vuesho.config.ts"
import { h } from "vue";
import { statusBadgesPlugin } from "vuesho/status-badges";

createSite(docs.toSource()).plugins(
  recommendedPreset(),
  statusBadgesPlugin({
    // [!code highlight:2]
    renderBadge: (status) =>
      h("span", { "data-status": status }, status === "new" ? "New" : status),
  }),
);
```

## Navbar [#navbar]

`ui.layoutProps` in the config sets the navbar's title and links, in every layout:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).config({
  ui: {
    layoutProps: {
      nav: { title: "Acme" },
      links: [
        { text: "Guide", url: "/guide", active: "nested-url" },
        { text: "Discord", url: "https://discord.gg/acme" },
        {
          type: "menu",
          text: "Community",
          items: [
            { text: "Forum", url: "https://forum.acme.dev", description: "Ask a question." },
            { text: "Showcase", url: "https://acme.dev/showcase" },
          ],
        },
      ],
    },
  },
});
```

<Tabs :items='["layoutProps","nav"]'>
<Tab value="layoutProps">
### LayoutProps

| Prop               | Type                                                                                                            | Description                                                                                 |
| ------------------ | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `nav?`             | `NavOptions \| undefined`                                                                                       | The navbar.                                                                                 |
| `links?`           | `LinkItem[] \| undefined`                                                                                       | The navbar's links.                                                                         |
| `githubUrl?`       | `string \| undefined`                                                                                           | The repository URL, which the navbar links to. Default: ``the one of `site.git` on GitHub`` |
| `colorModeSwitch?` | `{ enabled?: boolean; mode?: "light-dark" \| "light-dark-system"; } \| undefined`                               | The color mode switch, which a `fixed` color mode hides.                                    |
| `searchToggle?`    | `{ enabled?: boolean; sm?: { hideIfDisabled?: boolean; }; full?: { hideIfDisabled?: boolean; }; } \| undefined` | Whether the layout shows the search trigger buttons.                                        |
| `tabs?`            | `false \| AsJson<Omit<LayoutTab, "props" \| "$folder" \| "urls">>[] \| undefined`                               | The sidebar's tabs, or `false` for none. Default: `the root folders of the page tree`       |
</Tab>

<Tab value="nav">
### NavOptions

| Prop               | Type                                       | Description                                                                                                      |
| ------------------ | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `title?`           | `Renderable \| undefined`                  | Text, or a node like a logo, which the server renders to HTML. Default: `` `site.name` ``                        |
| `url?`             | `string \| undefined`                      | The URL the navbar title links to. Default: `the home page of the language`                                      |
| `enabled?`         | `boolean \| undefined`                     |                                                                                                                  |
| `transparentMode?` | `"always" \| "top" \| "none" \| undefined` | When the background of the navbar is transparent: always, at the top of the page only, or never. Default: `none` |
</Tab>
</Tabs>

`ui.layoutProps` reaches the browser as JSON, so a component with state, like a button that opens a dialog, goes in the [theme's `layoutProps`](/theme#layout-props) instead. A prop for one layout goes in a [layout wrapper](/layouts#layout-props).

### Links [#links]

`type` sets how a link renders. A link to another site opens in a new tab, and the build [validates](/markdown#link-validation) links to your own pages:

```ts title="vuesho.config.ts"
import { MessageCircle } from "@lucide/vue";

createSite(docs.toSource()).config({
  ui: {
    layoutProps: {
      links: [
        // A text link, the default, with an optional `icon` and `description`.
        { text: "Blog", url: "/blog" },
        // An icon, whose `label` is read by screen readers.
        {
          type: "icon",
          text: "Discord",
          label: "Discord",
          icon: MessageCircle,
          url: "https://discord.gg/acme",
        },
        // A button.
        { type: "button", text: "Get Started", url: "/" },
        // A menu of the links in `items`.
        { type: "menu", text: "More", items: [{ text: "Changelog", url: "/changelog" }] },
      ],
    },
  },
});
```

A text link has these fields, which the other types share:

### LinkItem

| Prop           | Type                                           | Description                                         |
| -------------- | ---------------------------------------------- | --------------------------------------------------- |
| `type?`        | `"main" \| undefined`                          |                                                     |
| `icon?`        | `Renderable \| undefined`                      |                                                     |
| `text`         | `string`                                       |                                                     |
| `description?` | `string \| undefined`                          |                                                     |
| `url`          | `string`                                       |                                                     |
| `active?`      | `"url" \| "nested-url" \| "none" \| undefined` | When the item is marked as active Default: `'url'`  |
| `external?`    | `boolean \| undefined`                         |                                                     |
| `on?`          | `"menu" \| "nav" \| "all" \| undefined`        | Restricts where the item is shown. Default: `'all'` |

### Logo [#logo]

`site.logo` shows an image before the site name in the navbar:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).config({
  // `public/logo.svg`, with the base path added
  site: { name: "Acme", logo: "/logo.svg" },
});
```

For a logo per [language](/i18n), or other markup, set `nav.title`:

```ts title="vuesho.config.ts"
import { h } from "vue";

createSite(docs.toSource()).config({
  ui: {
    // As a function, receives `{ lang }`. `nav.title` takes text, a component or a VNode.
    layoutProps({ lang }) {
      // [!code word:addBasePath]
      const src = this.addBasePath(lang === "cn" ? "/logo-cn.svg" : "/logo.svg");
      return { nav: { title: h("img", { src, alt: "Acme", height: 24 }) } };
    },
  },
});
```

### Repository [#repository]

`site.git` adds a link to the repository in the navbar, and an Open in GitHub link to each page's view options:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).config({
  site: {
    // The site is in `apps/docs` of github.com/acme/docs, on the branch `dev`.
    git: { user: "acme", repo: "docs", branch: "dev", dir: "apps/docs" },
  },
});
```

### GitOptions

| Prop        | Type                                               | Description                                                                                   |
| ----------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `provider?` | `"github" \| "gitlab" \| "bitbucket" \| undefined` | The Git hosting provider. Default: `"github"`                                                 |
| `url?`      | `string \| undefined`                              | The URL of a self-hosted instance, like `https://git.example.com`. Default: `the public host` |
| `user`      | `string`                                           | The repository owner or organization name.                                                    |
| `repo`      | `string`                                           | The repository name.                                                                          |
| `branch?`   | `string \| undefined`                              | The branch that source links use. Default: `"main"`                                           |
| `dir?`      | `string \| undefined`                              | The site's folder in the repository.                                                          |
