Skip to main content
The Container API allows you to render Astro components in isolation, useful for testing, server-side rendering, and on-demand page generation.

Importing

AstroContainer.create

Create a new container instance.
AstroContainerOptions
Container configuration options.
boolean
Enable streaming during rendering.Default: false
SSRLoadedRenderer[]
Array of renderers for UI framework components (React, Vue, etc.).Default: []
AstroContainerUserConfig
Subset of Astro configuration options.

Example

renderToString

Render a component to an HTML string.
AstroComponentFactory
required
The Astro component to render.
ContainerRenderOptions
Rendering options.
Request
Request object for the render. Used to populate Astro.request and Astro.url.
Record<string, string | undefined>
Route parameters for dynamic routes.
Record<string, any>
Props to pass to the component via Astro.props.
Record<string, any>
Slot content to pass to the component.
App.Locals
Locals object accessible via Astro.locals.
'page' | 'endpoint'
Type of route being rendered.Default: 'page'
boolean
When false, renders the component as a full page. When true, renders as a partial.Default: true

Example

renderToResponse

Render a component and return a Response object.
Accepts the same parameters as renderToString, but returns a Response object instead of a string.

Example

addServerRenderer

Manually add a server renderer to the container.
AddServerRenderer
required
Renderer options.
NamedSSRLoadedRendererValue | SSRLoadedRendererValue
required
The server renderer exported by an integration.
string
Name of the renderer. Required if the renderer is not a named renderer.

Example

addClientRenderer

Manually add a client renderer to the container for components using client:* directives.
AddClientRenderer
required
Client renderer options.
string
required
Name of the renderer. Must match the server renderer name.
string
required
Client-side entrypoint for the renderer.

Example

insertPageRoute

Register a page route in the container for use with Astro.rewrite().
string
required
The URL path that will render the component.
AstroComponentFactory
required
The component to render for this route.
Record<string, string | undefined>
Route parameters for dynamic routes.

Example

Testing Example

The Container API is particularly useful for testing:

Framework Component Example