If you want to catch all unknown routes (404 pages) in Nuxt and either show a custom message or redirect, you should create a special catch-all page.
the directory ----> /pages/[...all].vue
This file acts as a final fallback for any route that does not match any of the existing pages.
Example code that will redirect users upon landing on the unknown route. Note for this, the route method is in the onMounted function; hence, it's triggered when the page mounts.
<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
onMounted(() => {
router.replace('/')
})
</script>
<template>
<div></div>
</template>