title | description |
---|---|
Route Data Reference |
The full reference documentation for Starlight’s route data object. |
Starlight’s route data object contains information about the current page. Learn more about how Starlight’s data model works in the “Route Data” guide.
In Astro components, access route data from Astro.locals.starlightRoute
:
---
// src/components/Custom.astro
const { hasSidebar } = Astro.locals.starlightRoute;
---
In route middleware, access route data from the context object passed to your middleware function:
// src/routeData.ts
import { defineRouteMiddleware } from '@astrojs/starlight/route-data';
export const onRequest = defineRouteMiddleware((context) => {
const { hasSidebar } = context.locals.starlightRoute;
});
The starlightRoute
object has the following properties:
Type: 'ltr' | 'rtl'
Page writing direction.
Type: string
BCP-47 language tag for this page’s locale, e.g. en
, zh-CN
, or pt-BR
.
Type: string | undefined
The base path at which a language is served. undefined
for root locale slugs.
Type: string
The site title for this page’s locale.
Type: string
The value for the site title’s href
attribute, linking back to the homepage, e.g. /
.
For multilingual sites this will include the current locale, e.g. /en/
or /zh-cn/
.
Type: string
The slug for this page generated from the content filename.
This property is deprecated and will be removed in a future version of Starlight.
Migrate to the new Content Layer API by using Starlight’s docsLoader
and use the id
property instead.
Type: string
The slug for this page or the unique ID for this page based on the content filename if using the legacy.collections
flag.
Type: true | undefined
true
if this page is untranslated in the current language and using fallback content from the default locale.
Only used in multilingual sites.
Type: { dir: 'ltr' | 'rtl'; lang: string }
Locale metadata for the page content. Can be different from top-level locale values when a page is using fallback content.
The Astro content collection entry for the current page.
Includes frontmatter values for the current page at entry.data
.
entry: {
data: {
title: string;
description: string | undefined;
// etc.
}
}
Learn more about the shape of this object in Astro’s Collection Entry Type reference.
Type: SidebarEntry[]
Site navigation sidebar entries for this page.
Type: boolean
Whether or not the sidebar should be displayed on this page.
Type: { prev?: Link; next?: Link }
Links to the previous and next page in the sidebar if enabled.
Type: { minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined
Table of contents for this page if enabled.
Type: { depth: number; slug: string; text: string }[]
Array of all Markdown headings extracted from the current page.
Use toc
instead if you want to build a table of contents component that respects Starlight’s configuration options.
Type: Date | undefined
JavaScript Date
object representing when this page was last updated if enabled.
Type: URL | undefined
URL
object for the address where this page can be edited if enabled.