Composables
VitePress provides several Vue composables that give you access to app data, routing, and theme configuration.Core Composables
useData
Access page-level and site-level data.VitePressData<T>
Ref<SiteData<T>>
Site-level metadata and configuration
Ref<T>
The
themeConfig from .vitepress/config.jsRef<PageData>
Current page metadata including frontmatter, headers, and file paths
Ref<Record<string, any>>
Frontmatter data for the current page
Ref<Record<string, any>>
Dynamic route parameters (for data loading)
Ref<string>
Current page title (computed from frontmatter or first h1)
Ref<string>
Current page description
Ref<string>
Current language code
Ref<string>
Text direction (
ltr or rtl)Ref<string>
Current locale index (e.g.,
'root', 'zh', 'en')Ref<boolean>
Whether dark mode is currently active
Ref<string>
Current location hash (e.g.,
#introduction)useRoute
Access the current route information.Route (reactive object)
string
Current URL path (e.g.,
/guide/introduction.html)string
Current URL hash (e.g.,
#heading-anchor)string
Current URL query string (e.g.,
?tab=1&view=grid)PageData
Current page data object
Component | null
Current page component
useRouter
Access the router instance for programmatic navigation.Router
Route
Current route object (same as
useRoute())(to: string, options?) => Promise<void>
Navigate to a new URL
string
required
The URL to navigate to
boolean
default:"false"
Whether to smoothly scroll to the target position
boolean
default:"false"
Whether to replace the current history entry instead of pushing a new one
(to: string) => Awaitable<void | boolean>
Called before the route changes. Return
false to cancel navigation.(to: string) => Awaitable<void | boolean>
Called before the page component loads. Return
false to cancel.(to: string) => Awaitable<void>
Called after the page component loads but before update.
(to: string) => Awaitable<void>
Called after the route changes.