Skip to content

Commit 7127034

Browse files
committed
feat: add error page custom
1 parent 80e1652 commit 7127034

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

app/error.vue

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<script setup lang="ts">
2+
import { joinURL } from 'ufo'
3+
import type { NuxtError } from '#app'
4+
5+
const props = defineProps<{ error: NuxtError }>()
6+
7+
const baseURL = import.meta.dev ? '/' : useRuntimeConfig().app.baseURL
8+
9+
const isNotFound = computed(() => props.error?.statusCode === 404)
10+
const headline = computed(() =>
11+
isNotFound.value ? 'Page not found' : 'Something went wrong',
12+
)
13+
const description = computed(() =>
14+
isNotFound.value
15+
? 'Looks like this page took a wrong turn into hyperspace. The link may be broken or the page may have moved.'
16+
: props.error?.message || 'An unexpected error occurred. Please try again.',
17+
)
18+
19+
useHead({
20+
htmlAttrs: { lang: 'en' },
21+
meta: [
22+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
23+
{ name: 'robots', content: 'noindex' },
24+
],
25+
link: [
26+
{
27+
rel: 'icon',
28+
type: 'image/svg+xml',
29+
href: joinURL(baseURL, 'logo.svg'),
30+
},
31+
],
32+
})
33+
34+
useSeoMeta({
35+
title: () => headline.value,
36+
titleTemplate: '%s · Litestar',
37+
description: () => description.value,
38+
})
39+
40+
const handleError = () => clearError({ redirect: '/' })
41+
</script>
42+
43+
<template>
44+
<UApp>
45+
<div class="relative flex flex-col min-h-screen">
46+
<AppHeader />
47+
48+
<UMain class="relative flex-1 flex items-center justify-center">
49+
<HeroBackground
50+
class="absolute w-full -top-px text-primary shrink-0 -z-10"
51+
/>
52+
53+
<UContainer class="py-16 sm:py-24 lg:py-32">
54+
<UError
55+
as="section"
56+
:error="error"
57+
:clear="false"
58+
:ui="{
59+
root: 'text-center max-w-2xl mx-auto flex flex-col items-center',
60+
leading: 'mb-6',
61+
statusCode:
62+
'text-7xl sm:text-8xl font-bold text-primary leading-none',
63+
statusMessage:
64+
'text-3xl sm:text-4xl font-semibold text-highlighted mt-4',
65+
message: 'text-base sm:text-lg text-muted mt-4 max-w-prose',
66+
links: 'mt-10 flex flex-wrap justify-center gap-3',
67+
}"
68+
>
69+
<template #leading>
70+
<LitestarLogo class="block w-auto h-12 sm:h-14" />
71+
</template>
72+
73+
<template #statusMessage>
74+
{{ headline }}
75+
</template>
76+
77+
<template #message>
78+
{{ description }}
79+
</template>
80+
81+
<template #links>
82+
<UButton
83+
size="xl"
84+
trailing-icon="i-lucide-arrow-right"
85+
@click="handleError"
86+
>
87+
Back to home
88+
</UButton>
89+
<UButton
90+
to="https://docs.litestar.dev/"
91+
target="_blank"
92+
size="xl"
93+
color="neutral"
94+
variant="subtle"
95+
leading-icon="i-lucide-book-open"
96+
>
97+
Read the docs
98+
</UButton>
99+
</template>
100+
</UError>
101+
</UContainer>
102+
</UMain>
103+
104+
<AppFooter />
105+
</div>
106+
</UApp>
107+
</template>

0 commit comments

Comments
 (0)