[英]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:这是默认的错误页面:
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.