前端404页面的制作

1、背景

前端开发经常遇到输入路径不存在的问题,为此,把之前项目的404拿出来供大家参考。代码很简单,适合新手入手,效果如下:

2、代码引用的是element-plus框架

复制代码
<template>
    <div>
        <el-result icon="warning" title="404提示" sub-title="你找的页面不存在,点击下方按钮回家~">
            <template #extra>
                <el-button type="primary" @click="$router.push('/')">回到home页</el-button>
            </template>
        </el-result>
    </div>
</template>

3、路由配置

复制代码
import { createRouter, createWebHashHistory } from 'vue-router'

import Index from '~/pages/index.vue'
import NOTFOUND from '~/pages/404.vue'

const routes = [{
    path: "/",
    component: Index,
}, {
    path: '/:pathMatch(.*)*',
    name: 'NOTFOUND',
    component: NOTFOUND
}]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})


export default router
相关推荐
bearpping7 小时前
Nginx 配置:alias 和 root 的区别
前端·javascript·nginx
@大迁世界7 小时前
07.React 中的 createRoot 方法是什么?它具体如何运作?
前端·javascript·react.js·前端框架·ecmascript
January12077 小时前
VBen Admin Select 选择框选中后仍然显示校验错误提示的解决方案
前端·vben
. . . . .7 小时前
前端测试框架:Vitest
前端
xiaotao1318 小时前
什么是 Tailwind CSS
前端·css·css3
战南诚9 小时前
VUE中,keep-alive组件与钩子函数的生命周期
前端·vue.js
发现一只大呆瓜9 小时前
React-彻底搞懂 Redux:从单向数据流到 useReducer 的终极抉择
前端·react.js·面试
霍理迪9 小时前
Vue的响应式和生命周期
前端·javascript·vue.js
李剑一9 小时前
别再瞎写了!Cesium 模型 360° 环绕,4 套源码全公开,项目直接用
前端