Skip to content

SidebarItem.base overrides parent SidebarMulti.base instead of inheriting #4821

Closed as duplicate of#4114
@Ackerven

Description

@Ackerven

Is your feature request related to a problem? Please describe.

Sidebar define in code:

export type Sidebar = SidebarItem[] | SidebarMulti;

export interface SidebarMulti {
  [path: string]: SidebarItem[] | { items: SidebarItem[]; base: string };
}

export type SidebarItem = {
  text?: string;
  link?: string;
  items?: SidebarItem[];
  collapsed?: boolean;
  base?: string;
  docFooterText?: string;
  rel?: string;
  target?: string;
};

This is a direcotry structure:

└── misc
    ├── cap1.md
    ├── cap2
    │   ├── cap2-1.md
    │   └── index.md
    ├── index.md
    └── intro.md

I config sidebar in config.mts:

sidebar: {
  '/misc': {
    base: '/misc',
    items: [
      { text: 'Intro', link: '/intro' },
      { text: 'Cap1', link: '/cap1' },
      {
        text: 'Cap2',
        base: '/cap2',
        items: [{ text: 'Cap2.1', link: '/cap2-1' }],
      },
    ],
  },
}

Actual routes:

/misc/intro.html
/misc/cap1.html
/cap2/cap2-1.html

Describe the solution you'd like

In this setup, it looks like SidebarItem.base completely replaces the SidebarMulti.base, instead of working relative to it — which feels a bit unexpected.

Would it be possible for VitePress to support making nested base values inherit from the parent?

Something like this:

/misc/intro.html
/misc/cap1.html
/misc/cap2/cap2-1.html

That’d make things way more intuitive, especially when building out deeper folder structures.

Describe alternatives you've considered

No response

Additional context

Vitepress version: 2.0.0-alpha.7

Here is a minimal reproduction: https://stackblitz.com/edit/vite-yrm66kkm?file=docs%2F.vitepress%2Fconfig.ts

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions