mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-20 08:15:59 +00:00
docs: mention possibility of prerendering api routes (#31234)
This commit is contained in:
parent
fc03d2a92b
commit
b656c58b39
@ -144,6 +144,7 @@ You can use this at runtime within a [Nuxt context](/docs/guide/going-further/nu
|
||||
```vue [pages/index.vue]
|
||||
<script setup>
|
||||
prerenderRoutes(["/some/other/url"]);
|
||||
prerenderRoutes("/api/content/article/my-article");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -28,3 +28,19 @@ prerenderRoutes(['/', '/about'])
|
||||
::note
|
||||
In the browser, or if called outside prerendering, `prerenderRoutes` will have no effect.
|
||||
::
|
||||
|
||||
You can even prerender API routes which is particularly useful for full statically generated sites (SSG) because you can then `$fetch` data as if you have an available server!
|
||||
|
||||
```js
|
||||
prerenderRoutes('/api/content/article/name-of-article')
|
||||
|
||||
// Somewhere later in App
|
||||
const articleContent = await $fetch('/api/content/article/name-of-article', {
|
||||
responseType: 'json',
|
||||
})
|
||||
```
|
||||
|
||||
::warning
|
||||
Prerendered API routes in production may not return the expected response headers, depending on the provider you deploy to. For example, a JSON response might be served with an `application/octet-stream` content type.
|
||||
Always manually set `responseType` when fetching prerendered API routes.
|
||||
::
|
||||
|
Loading…
Reference in New Issue
Block a user