diff --git a/docs/themes/default/config.md b/docs/themes/default/config.md
index d6f8fdfdd6..680822cfea 100644
--- a/docs/themes/default/config.md
+++ b/docs/themes/default/config.md
@@ -391,10 +391,6 @@ export default {
- Set to `2` to include `
` and `` headers.
- ...
- The max value depends on which levels of headers you have extracted via [markdown.headers.level](https://v2.vuepress.vuejs.org/reference/config.html#markdown-headers).
-
- The default value of `markdown.headers.level` is `[2, 3]`, so the default max value of `sidebarDepth` is `2`.
-
You can override this global option via [sidebarDepth](./frontmatter.md#sidebardepth) frontmatter in your pages.
### editLink
diff --git a/docs/zh/themes/default/config.md b/docs/zh/themes/default/config.md
index 2dd5b939dc..a63d65ad65 100644
--- a/docs/zh/themes/default/config.md
+++ b/docs/zh/themes/default/config.md
@@ -392,10 +392,6 @@ export default {
- 设为 `2` 来包含 `` 和 `` 标题。
- ...
- 最大值取决于你通过 [markdown.headers.level](https://v2.vuepress.vuejs.org/zh/config.html#markdown-headers) 提取了哪些级别的标题。
-
- 由于 `markdown.headers.level` 的默认值是 `[2, 3]` ,因此 `sidebarDepth` 的默认最大值是 `2` 。
-
你可以通过页面的 [sidebarDepth](./frontmatter.md#sidebardepth) frontmatter 来覆盖这个全局配置。
### editLink
diff --git a/themes/theme-default/src/client/components/VPPage.vue b/themes/theme-default/src/client/components/VPPage.vue
index cc2b001b8a..89773236e8 100644
--- a/themes/theme-default/src/client/components/VPPage.vue
+++ b/themes/theme-default/src/client/components/VPPage.vue
@@ -2,6 +2,7 @@
import VPPageMeta from '@theme/VPPageMeta.vue'
import VPPageNav from '@theme/VPPageNav.vue'
import { Content } from 'vuepress/client'
+import { setupHeaders } from '../composables/index.js'
defineSlots<{
'top'?: (props: Record) => any
@@ -9,6 +10,8 @@ defineSlots<{
'content-top'?: (props: Record) => any
'content-bottom'?: (props: Record) => any
}>()
+
+setupHeaders()
diff --git a/themes/theme-default/src/client/composables/useSidebarItems.ts b/themes/theme-default/src/client/composables/useSidebarItems.ts
index e4cdabc325..7a9e1b94bf 100644
--- a/themes/theme-default/src/client/composables/useSidebarItems.ts
+++ b/themes/theme-default/src/client/composables/useSidebarItems.ts
@@ -1,14 +1,16 @@
import { useThemeLocaleData } from '@theme/useThemeData'
-import { keys, startsWith } from '@vuepress/helper/client'
-import { computed, inject, provide } from 'vue'
-import type { ComputedRef, InjectionKey } from 'vue'
+import { getHeaders, keys, startsWith } from '@vuepress/helper/client'
+import type { MenuItem } from '@vuepress/helper/client'
+import { computed, inject, onMounted, provide, ref, watch } from 'vue'
+import type { ComputedRef, InjectionKey, Ref } from 'vue'
import {
usePageData,
usePageFrontmatter,
useRoute,
useRouteLocale,
+ useRouter,
} from 'vuepress/client'
-import type { PageData, PageHeader } from 'vuepress/client'
+import type { PageData } from 'vuepress/client'
import { isPlainObject, isString } from 'vuepress/shared'
import type {
DefaultThemeNormalPageFrontmatter,
@@ -20,6 +22,46 @@ import type {
import type { SidebarHeaderItem, SidebarItem } from '../typings.js'
import { getAutoLink, isLinkInternal, resolvePrefix } from '../utils/index.js'
+export type HeadersRef = Ref