When rendering a page, Astro provides a runtime API specific to the current render. This includes useful information such as the current page URL as well as APIs to perform actions like redirecting to another page. InDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/withastro/docs/llms.txt
Use this file to discover all available pages before exploring further.
.astro components, this context is available from the Astro global object. Endpoint functions are also called with this same context object as their first argument.
Astro Global
TheAstro global object is available to all .astro files and provides access to the render context.
Astro.props
Object containing any values that have been passed as component attributes or from
getStaticPaths().src/components/Heading.astro
src/pages/index.astro
props also contains values passed from getStaticPaths():
src/pages/posts/[id].astro
Astro.params
Object containing the values of dynamic route segments matched for a request.
params returned by getStaticPaths() used for prerendering dynamic routes:
src/pages/posts/[id].astro
params can be any value matching the path segments in the dynamic route pattern:
src/pages/posts/[id].astro
Astro.url
A URL object constructed from the current
request.url value. Useful for interacting with individual properties of the request URL.src/pages/index.astro
url to create new URLs:
src/pages/index.astro
Astro.site
A URL made from
site in your Astro config. Returns undefined if not configured.src/pages/index.astro
Astro.clientAddress
The IP address of the request. Only available for routes rendered on demand.
src/pages/ip-address.astro
Astro.generator
The current version of Astro your project is running, in the format
"Astro v5.x.x".src/pages/site-info.astro
Astro.request
A standard Request object. Can be used to get the
url, headers, method, and even the body of the request.src/pages/index.astro
Astro.response
A standard ResponseInit object used to set the
status, statusText, and headers for a page’s response.status- The numeric status code (e.g.,200)statusText- The status message (e.g.,'OK')headers- A Headers instance for setting HTTP headers
Astro.redirect()
Returns a Response object that allows you to redirect to another page.
The URL path to redirect to.
The HTTP status code for the redirect.
A Response object for the redirect.
src/pages/account.astro
Astro.rewrite()
Serves content from a different URL or path without redirecting the browser to a new page.
The path, URL, or Request to rewrite to.
A Promise that resolves to the Response from the rewritten path.
src/pages/index.astro
src/pages/blog/index.astro
src/pages/blog/index.astro
Astro.locals
An object used to store and access arbitrary information during the lifecycle of a request.
src/middleware.ts
locals:
src/pages/Orders.astro
Astro.cookies
Utilities for reading and manipulating cookies for routes rendered on demand.
cookies.get()
Gets the cookie as an AstroCookie object.
cookies.has()
Checks whether a cookie exists.
cookies.set()
Sets the cookie key to the given value.
cookies.delete()
Invalidates a cookie by setting the expiration date in the past.
Astro.session
Allows data to be stored between requests for routes rendered on demand.
session.get()
Returns the value of the given key in the session.
src/components/Cart.astro
session.set()
Sets the value of the given key in the session.
src/pages/products/[slug].astro
session.regenerate()
Regenerates the session ID to prevent session fixation attacks.
src/pages/welcome.astro
session.destroy()
Destroys the session, deleting the cookie and the object from the backend.
src/pages/logout.astro
Astro.getActionResult()
Returns the result of an Action submission.
src/pages/index.astro
Astro.callAction()
Calls an Action handler directly from your Astro component.
src/pages/index.astro
APIContext
The same properties available onAstro are also available on the context object passed to endpoint functions and middleware.
src/pages/api/users.ts
src/pages/posts/[id].json.ts