Interface AstroSharedContext<Props, RouteParams>

interface AstroSharedContext<Props, RouteParams> {
    clientAddress: string;
    cookies: AstroCookies;
    currentLocale: undefined | string;
    getActionResult: (<TAccept, TInputSchema, TAction>(action) => undefined | Awaited<ReturnType<TAction["safe"]>>);
    locals: Locals;
    params: RouteParams;
    preferredLocale: undefined | string;
    preferredLocaleList: undefined | string[];
    props: Props;
    request: Request;
    url: URL;
    redirect(path, status?): Response;
    rewrite(rewritePayload): Promise<Response>;
}

Type Parameters

  • Props extends Record<string, any> = Record<string, any>
  • RouteParams extends Record<string, string | undefined> = Record<string, string | undefined>

Hierarchy (view full)

Properties

clientAddress: string

The address (usually IP address) of the user.

Throws an error if used within a static site, or within a prerendered page.

cookies: AstroCookies

Utility for getting and setting the values of cookies.

currentLocale: undefined | string

The current locale computed from the URL of the request. It matches the locales in i18n.locales, and returns undefined otherwise.

getActionResult: (<TAccept, TInputSchema, TAction>(action) => undefined | Awaited<ReturnType<TAction["safe"]>>)

Get action result on the server when using a form POST.

Type declaration

locals: Locals

Object accessed via Astro middleware

params: RouteParams

Route parameters for this request if this is a dynamic route.

preferredLocale: undefined | string

The current locale that is computed from the Accept-Language header of the browser (SSR Only).

preferredLocaleList: undefined | string[]

The list of locales computed from the Accept-Language header of the browser, sorted by quality value (SSR Only).

props: Props

List of props returned for this path by getStaticPaths (Static Only).

request: Request

Information about the current request. This is a standard Request object

url: URL

A full URL object of the request URL.

Methods

  • Redirect to another page (SSR Only).

    Parameters

    Returns Response

  • It rewrites to another page. As opposed to redirects, the URL won't change, and Astro will render the HTML emitted by the rerouted URL passed as argument.

    Example

    if (pageIsNotEnabled) {
    return Astro.rewrite('/fallback-page')
    }

    Parameters

    Returns Promise<Response>