Skip to content

Commit

Permalink
docs: show 404 for non-existent api pages
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed Feb 14, 2025
1 parent 85ed224 commit 812af2e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
30 changes: 22 additions & 8 deletions packages/docs/src/components/api/View.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<script setup lang="ts">
import type { PartData } from '@vuetify/api-generator/src/types'
import DefaultLayout from '@/layouts/default.vue'
import ErrorLayout from '@/layouts/404.vue'
const emit = defineEmits(['update:name'])
const sections = ['props', 'events', 'slots', 'exposed', 'sass', 'argument', 'modifiers', 'value'] as const
const route = useRoute()
const error = ref(false)
const name = computed(() => {
const name = route.params.name as string
if (name.endsWith('-directive')) return name.replace('-directive', '')
Expand All @@ -16,7 +19,12 @@
const component = shallowRef<any>({})
watch(name, async () => {
emit('update:name', name.value)
component.value = await getApi(name.value)
try {
component.value = await getApi(name.value)
error.value = false
} catch (err) {
error.value = true
}
}, { immediate: true })
function getApi (name: string): Promise<{ default: PartData }> {
Expand All @@ -25,11 +33,17 @@
</script>

<template>
<template v-for="section of sections" :key="section">
<ApiSection
v-if="section in component && Object.keys(component[section]).length"
:name="name"
:section="section"
/>
</template>
<ErrorLayout v-if="error" />
<DefaultLayout v-else>
<template #view>
<slot />
<template v-for="section of sections" :key="section">
<ApiSection
v-if="section in component && Object.keys(component[section]).length"
:name="name"
:section="section"
/>
</template>
</template>
</DefaultLayout>
</template>
3 changes: 3 additions & 0 deletions packages/docs/src/layouts/blank.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<router-view />
</template>
16 changes: 9 additions & 7 deletions packages/docs/src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
tag="section"
fluid
>
<router-view v-slot="{ Component }">
<v-fade-transition hide-on-leave>
<div :key="route.name">
<component :is="Component" />
</div>
</v-fade-transition>
</router-view>
<slot name="view">
<router-view v-slot="{ Component }">
<v-fade-transition hide-on-leave>
<div :key="route.name">
<component :is="Component" />
</div>
</v-fade-transition>
</router-view>
</slot>

<Backmatter v-if="hasBackmatter" :key="route.name" />
</v-container>
Expand Down
5 changes: 4 additions & 1 deletion packages/docs/src/pages/en/api/[name].md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
layout: blank
meta:
title: API
description: API documentation
Expand All @@ -9,6 +10,8 @@ meta:
const name = shallowRef('')
</script>

<ApiView v-on:update:name="name = $event">

# {{ name }} API

<PageFeatures />
Expand All @@ -19,4 +22,4 @@ meta:

<ApiSearch />

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

0 comments on commit 812af2e

Please sign in to comment.