nuxt- 配置404

直接layouts文件夹下加error.vue,定制自己想要的错误页面

  <template>
    <div>
      <h2 v-if="error.statusCode == 404">404页面不存在</h2>
      <h2 v-else>500服务器错误</h2>
      <nuxt-link to="/">返回首页</nuxt-link>
    <div>
  </template>
  <script>
    export default {
        props: ['error']
   }

当不存在当前页面时 会自动跳转
如果需要检验动态参数,可以在目的页面validate()方法里判断,也可以路由中间件中判断手动处理,比如我这边的多语言,输入不存在的多语言,也希望跳转404页面,可以在中间件写入

if (store.state.locales.indexOf(locale) === -1) {
    return error({
      message: 'This language could not be found.',
      statusCode: 404
    })
  }

猜你喜欢

转载自blog.csdn.net/weixin_33916256/article/details/86971175