Skip to content

Commit 383dac4

Browse files
committed
docs: show 404 for non-existent api pages
1 parent 85ed224 commit 383dac4

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed
+22-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<script setup lang="ts">
22
import type { PartData } from '@vuetify/api-generator/src/types'
3+
import DefaultLayout from '@/layouts/default.vue'
4+
import ErrorLayout from '@/layouts/404.vue'
35
46
const emit = defineEmits(['update:name'])
57
68
const sections = ['props', 'events', 'slots', 'exposed', 'sass', 'argument', 'modifiers', 'value'] as const
79
810
const route = useRoute()
911
12+
const error = ref(false)
1013
const name = computed(() => {
1114
const name = route.params.name as string
1215
if (name.endsWith('-directive')) return name.replace('-directive', '')
@@ -16,7 +19,12 @@
1619
const component = shallowRef<any>({})
1720
watch(name, async () => {
1821
emit('update:name', name.value)
19-
component.value = await getApi(name.value)
22+
try {
23+
component.value = await getApi(name.value)
24+
error.value = false
25+
} catch (err) {
26+
error.value = true
27+
}
2028
}, { immediate: true })
2129
2230
function getApi (name: string): Promise<{ default: PartData }> {
@@ -25,11 +33,17 @@
2533
</script>
2634

2735
<template>
28-
<template v-for="section of sections" :key="section">
29-
<ApiSection
30-
v-if="section in component && Object.keys(component[section]).length"
31-
:name="name"
32-
:section="section"
33-
/>
34-
</template>
36+
<ErrorLayout v-if="error" />
37+
<DefaultLayout v-else>
38+
<template #view>
39+
<slot />
40+
<template v-for="section of sections" :key="section">
41+
<ApiSection
42+
v-if="section in component && Object.keys(component[section]).length"
43+
:name="name"
44+
:section="section"
45+
/>
46+
</template>
47+
</template>
48+
</DefaultLayout>
3549
</template>

packages/docs/src/layouts/default.vue

+9-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
tag="section"
2121
fluid
2222
>
23-
<router-view v-slot="{ Component }">
24-
<v-fade-transition hide-on-leave>
25-
<div :key="route.name">
26-
<component :is="Component" />
27-
</div>
28-
</v-fade-transition>
29-
</router-view>
23+
<slot name="view">
24+
<router-view v-slot="{ Component }">
25+
<v-fade-transition hide-on-leave>
26+
<div :key="route.name">
27+
<component :is="Component" />
28+
</div>
29+
</v-fade-transition>
30+
</router-view>
31+
</slot>
3032

3133
<Backmatter v-if="hasBackmatter" :key="route.name" />
3234
</v-container>

packages/docs/src/pages/en/api/[name].md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
layout: blank
23
meta:
34
title: API
45
description: API documentation
@@ -9,6 +10,8 @@ meta:
910
const name = shallowRef('')
1011
</script>
1112

13+
<ApiView v-on:update:name="name = $event">
14+
1215
# {{ name }} API
1316

1417
<PageFeatures />
@@ -19,4 +22,4 @@ meta:
1922

2023
<ApiSearch />
2124

22-
<ApiView v-on:update:name="name = $event" />
25+
</ApiView>

0 commit comments

Comments
 (0)