Skip to content

Latest commit

 

History

History
151 lines (89 loc) · 3.79 KB

route-data.md

File metadata and controls

151 lines (89 loc) · 3.79 KB
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;
});

starlightRoute

The starlightRoute object has the following properties:

dir

Type: 'ltr' | 'rtl'

Page writing direction.

lang

Type: string

BCP-47 language tag for this page’s locale, e.g. en, zh-CN, or pt-BR.

locale

Type: string | undefined

The base path at which a language is served. undefined for root locale slugs.

siteTitle

Type: string

The site title for this page’s locale.

siteTitleHref

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/.

slug

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.

id

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.

isFallback

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.

entryMeta

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.

entry

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.

sidebar

Type: SidebarEntry[]

Site navigation sidebar entries for this page.

hasSidebar

Type: boolean

Whether or not the sidebar should be displayed on this page.

pagination

Type: { prev?: Link; next?: Link }

Links to the previous and next page in the sidebar if enabled.

toc

Type: { minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined

Table of contents for this page if enabled.

headings

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.

lastUpdated

Type: Date | undefined

JavaScript Date object representing when this page was last updated if enabled.

editUrl

Type: URL | undefined

URL object for the address where this page can be edited if enabled.