Sidebar
Introduction
Pass sidebar option to theme default to configure sidebar. There are two ways to set up the sidebar:
- Auto-generated — Automatically scan your routes directory and build the sidebar from your file structure and frontmatter
- Manual — Explicitly define every sidebar item in your Vite config
Auto-generated sidebar
Set sidebar to { enabled: true } to let SveltePress automatically generate the sidebar by scanning your src/routes/ directory.
import { } from '@sveltepress/theme-default'
import { } from '@sveltepress/vite'
import { } from 'vite'
export default ({
: [
({
: ({
: {
: true,
},
}),
}),
],
}) SveltePress will detect top-level route directories (e.g. /guide/, /reference/) and build sidebar groups from them automatically.
Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | — | Set to true to enable auto sidebar |
routesDir | string | 'src/routes' | Custom routes directory path |
roots | string[] | auto-detected | Root paths to generate sidebar for, e.g. ['/guide/', '/reference/']. If not specified, auto-detect from top-level route directories |
sidebar: {
enabled: true,
routesDir: 'src/routes',
roots: ['/guide/', '/reference/'],
} Frontmatter control
Use frontmatter in your +page.md files to control how pages appear in the auto-generated sidebar.
---
title: Getting Started
order: 1
sidebar: true
sidebarTitle: Start Here
collapsible: true
--- | Field | Type | Default | Description |
|---|---|---|---|
title | string | Inferred from filename | Page title, also used as sidebar label |
sidebarTitle | string | — | Override the sidebar label (takes precedence over title) |
order | number | 100 | Sort order within the same level. Lower numbers appear first |
sidebar | boolean | true | Set to false to exclude this page from the sidebar |
collapsible | boolean | — | Whether the sidebar group is collapsible |
If no title or sidebarTitle is provided, the directory name is humanized (e.g. getting-started → Getting Started).
When using auto sidebar in dev mode, adding or removing route files will automatically regenerate the sidebar — no restart needed.
Manual sidebar
Manually define the sidebar structure in your Vite config. This gives you full control over titles, links, grouping, and ordering.
The links configured will be auto prefixed with base
You need to set paths.relative to false
import adapter from '@sveltejs/adapter-static'
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
paths: {
relative: false,
},
},
}
export default config import { } from '@sveltepress/theme-default'
import { } from '@sveltepress/vite'
import { } from 'vite'
export default ({
: [
({
: ({
: {
'/foo/': [
{
: 'Bar',
: '/foo/bar/',
},
{
: 'Zoo',
: true,
: [
{
: 'Sub item',
: '/sub/item/link',
},
],
},
{
: 'External github page',
: 'https://github.com',
},
],
},
}),
}),
],
}) title
The sidebar item title
to
The link address
Unlike the navbar item, sidebar item use the Link component.
Which means link starts with http(s) would be auto recognized as external links.
collapsible
Determine whether the sidebar group is collapsible or not. Default is false
items
Sub items
Nested items is supported