首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义NuxtError : NuxtJs: NuxtJs:NuxtJs

未定义NuxtError : NuxtJs: NuxtJs:NuxtJs
EN

Stack Overflow用户
提问于 2020-09-11 20:02:42
回答 1查看 2.7K关注 0票数 3

我是NuxtJs的新手。我想测试nuxt-link是如何工作的,所以我故意将nuxt-link放在一个不起作用的路由上,希望被重定向到默认的404页面。我将下面这一行放入pages/index.vue文件:

代码语言:javascript
复制
<nuxt-link to='/asksdkjd'>ssss</nuxt-link>

并且它像this:一样以铬合金显示

单击链接后,我在控制台中看到以下错误:

代码语言:javascript
复制
ReferenceError: NuxtError is not defined
at Vue.errorChanged (App.js?efe7:173)
at Watcher.run (vue.runtime.esm.js?2b0e:4568)
at flushSchedulerQueue (vue.runtime.esm.js?2b0e:4310)
at Array.eval (vue.runtime.esm.js?2b0e:1980)
at flushCallbacks (vue.runtime.esm.js?2b0e:1906)

vue.runtime.esm.js?2b0e:619 [Vue warn]: You may have an infinite update loop in watcher with expression "nuxt.err"
(found in <Root>)

这是当我被重定向到链接时这个错误显示的error screenshot,因为您可以在url栏中看到无效链接。它不会呈现默认的404页面。但是当我点击刷新时,我可以看到404页面的(sceenshot)

这是我在安装这个新项目时生成的nuxt.config.js文件(我省略了注释)。

代码语言:javascript
复制
export default {
  mode: 'universal',
  target: 'static',
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  css: [
  ],
  plugins: [
  ],
  components: true,
  buildModules: [
  ],
  modules: [
  ],
  build: {
  }
}

我已经用谷歌搜索这个错误很长一段时间了,但没有找到任何东西。我也尝试过firefox,但同样的问题也发生了。希望你们能帮上忙。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-09-13 04:11:36

定义你的错误页面。

创建此文件:layout/error.vue

代码语言:javascript
复制
<template>
  <div class="container">
    <div v-if="error.statusCode === 404">
      <h1>Page not found</h1>
      <p>{{ error.message }}</p>
    </div>
    <div v-else>
      <h1>An error occurred</h1>
    </div>
    <n-link to="/">Home page</n-link>
  </div>
</template>

<script>
export default {
  props: ['error'],
  layout: 'default' // If you prefers you can set a custom layout for the error page
}
</script>

更多信息:查看有关error page的nuxt文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63846716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档