Skip to main content
The Astro global object is available in all .astro components and provides access to request data, routing information, and utilities for rendering.

Properties

Record<string, any>
Component props passed from parent components or from getStaticPaths().
Request
A standard Request object containing information about the current request.
URL
A URL object constructed from the current request URL. Equivalent to new URL(Astro.request.url).
Record<string, string | undefined>
An object containing the values of dynamic route segments matched for this request.
URL | undefined
The site from your Astro config, parsed as a URL instance. Returns undefined if not set.
string
A string representing the Astro version, in the format "Astro v5.x.x".
AstroCookies
Utilities for reading and manipulating cookies in on-demand routes.
App.Locals
An object that middleware can use to store extra information related to the request.
string
The IP address of the client making the request. Only available in on-demand routes.
ResponseInit & { readonly headers: Headers }
A standard ResponseInit object for modifying the outgoing response.
AstroComponentFactory
Allows a component to recursively call itself.
object
An object containing utility functions for working with slotted children.

Methods

(slotName: string) => boolean
Check whether content for a slot name exists.
(slotName: string, args?: any[]) => Promise<string>
Asynchronously renders the contents of a slot to a string of HTML.
string | undefined
The current locale computed from the URL of the request. Only available when i18n routing is configured.
string | undefined
The best match between visitor’s browser language preferences and supported locales. Only available in on-demand routes.
string[] | undefined
List of all locales that are both requested by the browser and supported by the site. Only available in on-demand routes.
boolean
Whether the current route is prerendered or not.
string
The route pattern for the current route, stripped of the srcDir and pages folder.
string
The original pathname before any rewrites were applied. Useful for tracking the original URL.

Methods

(path: string, status?: number) => Response
Create a response that redirects to another page.
(rewritePayload: RewritePayload) => Promise<Response>
Serve content from a different URL or path without redirecting the browser.
<TAction>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>
Call an Action handler directly from your Astro component.
<TAction>(action: TAction) => ActionReturnType<TAction> | undefined
Get the result of an Action submission when using a form POST.

Session

AstroSession | undefined
Utilities for handling sessions in on-demand rendered routes.

CSP (Content Security Policy)

object | undefined
Utilities to control CSP headers. Only available when CSP is enabled in config.

Methods

(directive: string) => void
Add a specific CSP directive to the route being rendered.
(payload: string) => void
Set the resource for the style-src directive.
(hash: string) => void
Insert a single style hash to the route being rendered.
(resource: string) => void
Set the resource for the script-src directive.
(hash: string) => void
Insert a single script hash to the route being rendered.