Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/content/docs/zh-cn/reference/adapter-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,18 @@ export function start(manifest) {

该模块提供以下几个方法:

##### `app.render(request, routeData, locals)`
##### `app.render(request, { routeData, locals })`

此方法用于匹配符合请求的 Astro 页面,并返回一个 Promise 对象给 [Response](https://developer.mozilla.org/zh-CN/docs/Web/API/Response) 。该方法对于不渲染页面的 API 路由同样适用。

```js
const response = await app.render(request);
```

方法拥有一个必传参数 `request`,和两个可选参数 [`routeData`](/zh-cn/reference/integrations-reference/#routedata-类型参考) 以及 [`locals`](/zh-cn/guides/middleware/#locals)
方法拥有一个必传参数 `request`,和一个传入 [`routeData`](/zh-cn/reference/integrations-reference/#routedata-类型参考) 以及 [`locals`](/zh-cn/guides/middleware/#astrolocals) 的可选参数

如果你已经明确需要渲染的路由,可以通过传入 `routeData` 参数,跳过内部调用 [`app.match`](#appmatchrequest) 进行匹配的步骤。

如需使用 `locals` 参数,必须将其作为第三个参数传入。如果不需要指定路由的话,可以将 `routeData` 参数设置为 `undefined`。

下方示例尝试解析 `x-private-header` 请求头,并将其传入 `locals` 中。在此之后,它就可以作为参数被任意[中间件](/zh-cn/guides/middleware/)使用了。

```js
Expand All @@ -214,7 +212,7 @@ try {
locals = JSON.parse(privateHeader);
}
} finally {
const response = await app.render(request, undefined, locals);
const response = await app.render(request, { locals });
}
```

Expand Down