Astro global object is available in all .astro components and provides access to request data, routing information, and utilities for rendering.
Properties
Component props passed from parent components or from
getStaticPaths().A URL object constructed from the current request URL. Equivalent to
new URL(Astro.request.url).An object containing the values of dynamic route segments matched for this request.
The
site from your Astro config, parsed as a URL instance. Returns undefined if not set.A string representing the Astro version, in the format
"Astro v5.x.x".Utilities for reading and manipulating cookies in on-demand routes.
An object that middleware can use to store extra information related to the request.
The IP address of the client making the request. Only available in on-demand routes.
A standard ResponseInit object for modifying the outgoing response.
Allows a component to recursively call itself.
An object containing utility functions for working with slotted children.
Methods
Check whether content for a slot name exists.
Asynchronously renders the contents of a slot to a string of HTML.
The current locale computed from the URL of the request. Only available when i18n routing is configured.
The best match between visitor’s browser language preferences and supported locales. Only available in on-demand routes.
List of all locales that are both requested by the browser and supported by the site. Only available in on-demand routes.
Whether the current route is prerendered or not.
The route pattern for the current route, stripped of the
srcDir and pages folder.The original pathname before any rewrites were applied. Useful for tracking the original URL.
Methods
Create a response that redirects to another page.
Serve content from a different URL or path without redirecting the browser.
Astro.callAction
<TAction>(action: TAction, input: Parameters<TAction>[0]) => Promise<ActionReturnType<TAction>>
Call an Action handler directly from your Astro component.
Get the result of an Action submission when using a form POST.
Session
Utilities for handling sessions in on-demand rendered routes.
CSP (Content Security Policy)
Utilities to control CSP headers. Only available when CSP is enabled in config.
Methods
Add a specific CSP directive to the route being rendered.
Set the resource for the
style-src directive.Insert a single style hash to the route being rendered.
Set the resource for the
script-src directive.Insert a single script hash to the route being rendered.