Nuxt V3 Nuxtlink Navigate 404 No Error Shown (createError on client side)

Dec 27, 2022

Whenever I click on <NuxtLink :to="/missing">Go to missing pages</NuxtLink>, I notice nothing happens.

If I refresh the page to trigger server side render, I get the 404 error page.

I check the developer console, I see Uncaught (in promise) Error: Not Found at createError. I have a catch all page pages/[slug].vue which throw createError whenever the page data is not found.

Creating ~error.vue doesn't help.

After checking createError documentation I found the following.

If you throw an error created with createError:
- on server-side, it will trigger a full-screen error page which you can clear with clearError.
- on client-side, it will throw a non-fatal error for you to handle. If you need to trigger a full-screen error page, then you can do this by setting fatal: true.

So I need to add fatal: true to trigger error page on client side (NuxtLink click to navigate).

<script setup>const { path } = useRoute();const { data, error } = await useAsyncData(`content-${path}`, () => {  return queryContent().where({ _path: path }).findOne();});if (error.value) {  throw createError({    statusCode: 404,    statusMessage: 'Not Found',    fatal: true  })}</script><template>  <main>    <ContentRenderer v-if="data" :value="data" class="article" />  </main></template>

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.