Reputation: 1067
If Route-Validation returns false
, it will show /error.vue
but not render the component of /:pathMatch(.*)*
.
~/plugins/route.ts
:
export default defineNuxtPlugin(() => {
useRouter().addRoute({
path: '/:pathMatch(.*)*',
component: () => import('~/pages/404.vue'),
});
return {};
});
~/pages/404.vue
:
<template>err</template>
~/pages/problem/[id]/index.vue
:
<script lang="ts" setup>
definePageMeta({
validate(route) {
return new RegExp('^\\d+$').test(String(route.params.id));
},
});
</script>
<template>problem</template>
Navigation Tests:
/foo
-> render 404 page/foo/bar
-> render 404 page/problem/foo
-> render Nuxt Error Page/problem/foo/bar
-> render 404 pageUpvotes: 0
Views: 1587
Reputation: 1067
Offical reply: https://github.com/nuxt/nuxt/issues/19327
This is by design.
Upvotes: 0
Reputation: 1944
Nuxt routing is based on directories. "Catch-all" doesn't apply recursively.
What you seek is:
/pages
├─ /foo
│ └─ [nested].vue
└─ [root].vue
Upvotes: 0