2023-03-08 21:13:06 +00:00
|
|
|
---
|
|
|
|
title: "<NuxtClientFallback>"
|
2023-11-18 20:24:13 +00:00
|
|
|
description: "Nuxt provides the <NuxtClientFallback> component to render its content on the client if any of its children trigger an error in SSR"
|
2023-10-18 10:59:43 +00:00
|
|
|
links:
|
|
|
|
- label: Source (client)
|
|
|
|
icon: i-simple-icons-github
|
|
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/client-fallback.client.ts
|
|
|
|
size: xs
|
|
|
|
- label: Source (server)
|
|
|
|
icon: i-simple-icons-github
|
|
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/client-fallback.server.ts
|
|
|
|
size: xs
|
2023-03-08 21:13:06 +00:00
|
|
|
---
|
|
|
|
|
2024-02-21 17:09:45 +00:00
|
|
|
::note{to="/docs/guide/going-further/experimental-features#clientfallback"}
|
2023-03-08 21:13:06 +00:00
|
|
|
This component is experimental and in order to use it you must enable the `experimental.clientFallback` option in your `nuxt.config`.
|
|
|
|
::
|
|
|
|
|
|
|
|
## Events
|
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
- `@ssr-error`: Event emitted when a child triggers an error in SSR. Note that this will only be triggered on the server.
|
2023-03-08 21:13:06 +00:00
|
|
|
|
|
|
|
```vue
|
|
|
|
<template>
|
|
|
|
<NuxtClientFallback @ssr-error="logSomeError">
|
|
|
|
<!-- ... -->
|
|
|
|
</NuxtClientFallback>
|
|
|
|
</template>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Props
|
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
- `placeholderTag` | `fallbackTag`: Specify a fallback tag to be rendered if the slot fails to render.
|
2023-03-08 21:13:06 +00:00
|
|
|
- **type**: `string`
|
|
|
|
- **default**: `div`
|
2023-10-18 10:59:43 +00:00
|
|
|
- `placeholder` | `fallback`: Specify fallback content to be rendered if the slot fails to render.
|
2023-03-08 21:13:06 +00:00
|
|
|
- **type**: `string`
|
2023-10-18 10:59:43 +00:00
|
|
|
- `keepFallback`: Keep the fallback content if it failed to render server-side.
|
2023-05-14 21:22:54 +00:00
|
|
|
- **type**: `boolean`
|
|
|
|
- **default**: `false`
|
2023-03-08 21:13:06 +00:00
|
|
|
|
|
|
|
```vue
|
|
|
|
<template>
|
|
|
|
<!-- render <span>Hello world</span> server-side if the default slot fails to render -->
|
|
|
|
<NuxtClientFallback fallback-tag="span" fallback="Hello world">
|
|
|
|
<BrokeInSsr />
|
|
|
|
</NuxtClientFallback>
|
|
|
|
</template>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Slots
|
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
- `#fallback`: specify content to be displayed server-side if the slot fails to render.
|
2023-03-08 21:13:06 +00:00
|
|
|
|
|
|
|
```vue
|
|
|
|
<template>
|
|
|
|
<NuxtClientFallback>
|
|
|
|
<!-- ... -->
|
|
|
|
<template #fallback>
|
|
|
|
<!-- this will be rendered on server side if the default slot fails to render in ssr -->
|
|
|
|
<p>Hello world</p>
|
|
|
|
</template>
|
|
|
|
</NuxtClientFallback>
|
|
|
|
</template>
|
|
|
|
```
|