-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherror.vue
More file actions
66 lines (57 loc) · 1.68 KB
/
error.vue
File metadata and controls
66 lines (57 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
<main class="flex flex-col items-center justify-center h-svh px-4">
<AppLogo
class="mb-16"
:height="64"
/>
<p
v-if="props.error?.statusCode"
class="mb-4 text-8xl font-semibold font-mono text-center"
v-text="props.error.statusCode"
/>
<p
class="text-2xl text-center"
v-text="props.error?.message"
/>
<code
v-if="props.error?.data?.rawMessage"
class="block not-first:mt-4 px-2 py-1 text-xs font-mono font-medium rounded-md border border-gray-300 bg-gray-100 break-all whitespace-pre-wrap"
v-text="props.error?.data?.rawMessage"
/>
<UButton
class="mt-8"
:label="backButtonLabel"
:to="backButtonRoute"
size="xl"
/>
</main>
</template>
<script setup lang="ts">
import type { NuxtError } from '#app'
const route = useRoute()
const localeRoute = useLocaleRoute()
const getRouteBaseName = useRouteBaseName()
const { t: $t } = useI18n()
const props = defineProps({
error: Object as () => NuxtError<{ rawMessage?: string }>,
})
const routeBaseName = computed(() => getRouteBaseName(route))
const backButtonLabel = computed(() => {
if (routeBaseName.value?.startsWith('store')) {
return $t('error_back_to_bookstore_button_label')
}
if (routeBaseName.value?.startsWith('shelf')) {
return $t('error_back_to_bookshelf_button_label')
}
return $t('error_back_to_home_button_label')
})
const backButtonRoute = computed(() => {
if (routeBaseName.value?.startsWith('store')) {
return localeRoute({ name: 'store' })
}
if (routeBaseName.value?.startsWith('shelf')) {
return localeRoute({ name: 'shelf' })
}
return localeRoute({ name: 'index' })
})
</script>