简体   繁体   English

Nuxt3 默认错误页面无法用 layouts/error.vue 覆盖

[英]Nuxt3 default error page can't be overwritten with layouts/error.vue

I have created a layouts/error.vue file that I'd like to use as my error page in my Nuxt3 app.我创建了一个 layouts/error.vue 文件,我想将其用作我的 Nuxt3 应用程序中的错误页面。

But for some reason, the default error page keeps loading up every time.但由于某种原因,默认错误页面每次都会加载。

This is the default error page:这是默认的错误页面: 默认的 nuxt3 错误页面

This is the code I have in my error.vue file:这是我的 error.vue 文件中的代码:

<template>
  <div class="container">
    <h1 v-if="error.statusCode === 404">Page not found</h1>
    <h1 v-else>An error occurred</h1>
    <NuxtLink to="/">Home page</NuxtLink>
  </div>
</template>

<script>
export default {
  props: ["error"],
};
</script>

Every developer I have seen so far or read the docs explains this as a pretty simple thing to do by creating a folder and a file, so this might have to do something with my setup tho.到目前为止,我见过或阅读过文档的每个开发人员都将此解释为通过创建文件夹和文件来完成的一件非常简单的事情,所以这可能与我的设置有关。

Anyway, could any of you point me to the right direction here please?无论如何,你们中有人能指出我正确的方向吗?

You created error file in layouts folder which stands for Nuxt version 2.您在代表 Nuxt 版本 2 的layouts文件夹中创建了error文件。

For Nuxt 3 you need to keep it next to app.vue file in your root folder.对于 Nuxt 3,您需要将其保存在根文件夹中的 app.vue 文件旁边。 As documentation says:正如文档所说:

You can customize this error page by adding ~/error.vue in the source directory of your application, alongside app.vue.您可以通过在应用程序的源目录中添加 ~/error.vue 和 app.vue 来自定义此错误页面。 This page has a single prop - error which contains an error for you to handle.这个页面只有一个 prop - error ,它包含一个你要处理的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从/ pages重定向到layouts / error.vue? - How to redirect from /pages to layouts/error.vue? 这个错误会在生产 Nuxt3 期间导致问题吗 - Will this error cause issues during production Nuxt3 Nuxt3 路由器不会将用户推送到特定页面 - Nuxt3 router doesn't push user to certain page 如何在 Nuxt3 中使用@heroicons/vue? - How to use @heroicons/vue in Nuxt3? Nuxt 错误:无法读取 null 的属性(读取“addEventListener”)default.vue 和 index.vue 未呈现 - Nuxt Error : Cannot read properties of null (reading 'addEventListener') default.vue and index.vue not rendering Nuxt 和 Vue Apollo。 如何通过重定向到 404/400/500 错误页面来处理 Smart Query 中的错误? 我们能捕捉到这样的错误吗? - Nuxt and Vue Apollo. How to handle errors inside Smart Query with redirection to 404/400/500 error page? Can we catch such errors? 创建 nuxt3 项目时出错。 无法从注册表下载模板 - Error while creating nuxt3 project. Failed to download template from registry 在组合 Api vue 3 nuxt3 中设置发射值 - set emitted value in compositition Api vue 3 nuxt3 layouts\default.vue 会在我重启 nuxt.js 服务器后重置 - layouts\default.vue will be reset after I restart the nuxt.js server NUXT - asyncData 和 vue Actions 错误处理 - NUXT - asyncData and vue Actions error handling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM