komal.nakrani
Browse Themes
ThemesCategoriesDocsBlogTips & Tricks
Astro Fundamentals••By Komal Nakrani

The Astro Global: Every Property on One Page

The Astro global object explained: Astro.props, params, url, site, request, cookies, locals, slots, redirect, rewrite, session and more, with what each one returns.

#Astro#Cheatsheet#Astro Global

The Astro global is the Astro object available in every .astro file’s frontmatter and template. It gives you the component’s props, the current URL and request, cookies, slots, locale, and helpers to redirect or rewrite. Endpoints and middleware get most of the same values on their context argument instead. This page lists every property in Astro 7, grouped by job, with what it returns and when it’s useful.

Key Takeaways

  • Astro.props and Astro.slots describe the component; most other properties describe the request.
  • On prerendered pages, request-specific values reflect the build, not a visitor.
  • Astro.site is your configured site; Astro.url is the URL being rendered.
  • The Astro global isn’t available inside getStaticPaths().

Component

Property Returns Use
Astro.props Props passed to the component (or from getStaticPaths()) Read inputs
Astro.slots.has(name) boolean Render wrappers only when a slot is filled
Astro.slots.render(name, args?) Promise of HTML string Render a slot to a string, optionally passing data
Astro.self The current component Recursive components, like nested menus
---
interface Props { title: string }
const { title } = Astro.props;
---
{Astro.slots.has('footer') && <footer><slot name="footer" /></footer>}

URL and routing

Property Returns
Astro.url URL of the current page
Astro.originPathname Original pathname before any rewrite
Astro.params Dynamic route segments
Astro.routePattern Route pattern, e.g. /blog/[slug]
Astro.site URL from the site config, or undefined
Astro.isPrerendered true if this page was prerendered
Astro.generator Generator string, e.g. for a meta tag
<link rel="canonical" href={new URL(Astro.url.pathname, Astro.site)} />
<meta name="generator" content={Astro.generator} />

Canonical patterns are covered in canonical URLs in Astro.

Request and response (on-demand pages)

Property Returns
Astro.request Standard Request (method, headers, body)
Astro.response Mutable status, statusText and headers for the page response
Astro.clientAddress Visitor IP, when the adapter supports it
Astro.cookies Get, set, delete and check cookies
Astro.locals Data set by middleware for this request
Astro.session Server-side session storage (needs a driver)
---
export const prerender = false;
Astro.response.headers.set('Cache-Control', 'private, no-store');
const theme = Astro.cookies.get('theme')?.value ?? 'light';
const user = Astro.locals.user;
---

Astro.clientAddress isn’t available on prerendered pages; Astro throws a dedicated error if you try.

Control flow

Method Does
Astro.redirect(path, status?) Returns a redirect response (default 302)
Astro.rewrite(path) Renders another route at the current URL
Astro.callAction(action, input) Calls an action from server code
Astro.getActionResult(action) Reads the result of a form submitted to an action
---
if (!Astro.locals.user) return Astro.redirect('/login/');
---

Calling an action directly instead of through callAction() causes this error.

Internationalisation

Property Returns
Astro.currentLocale Locale of the current route
Astro.preferredLocale Best match from the Accept-Language header
Astro.preferredLocaleList All acceptable locales, in order

Security and logging

Property Use
Astro.csp Add hashes, directives and resources when CSP is enabled
Astro.logger Log through Astro’s logger (info, warn, error)

Where each value is available

Page frontmatter Component Endpoint/middleware
Props, slots, self Yes Yes No
URL, params, site Yes Yes context.url, context.params, context.site
Request, cookies, locals, session Yes Yes context.*
redirect, rewrite Yes (pages) No context.redirect, context.rewrite

Not available in getStaticPaths()

---
export async function getStaticPaths() {
  // Astro.url, Astro.props, Astro.site: not available here
}
---

See Unavailable Astro global in getStaticPaths().

For components and slots in depth, read the Astro components guide; for request-time features, the Astro SSR guide. The API reference documents every property’s type.

FAQ

Is Astro.request available on static pages?

It exists, but at build time there’s no visitor, so headers and cookies are empty. Use on-demand rendering for per-request data.

What is the difference between Astro.url and Astro.site?

Astro.url is the URL of the page being rendered. Astro.site is the site value from your config, used to build absolute production URLs.