前端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
相关推荐
粉末的沉淀10 分钟前
css:倒影倾斜效果
前端·css
zandy10111 小时前
如何快速入门-衡石科技分析平台
服务器·前端·科技·数据库管理员
邝邝邝邝丹1 小时前
React学习———React Router
前端·学习·react.js
Yvonne爱编码2 小时前
CSS- 2.1 实战之图文混排、表格、表单
前端·css·html·github·状态模式·html5·hbuilder
前端小巷子2 小时前
CSS面试题汇总
前端·css·面试
绝美焦栖2 小时前
vue复杂数据类型多层嵌套的监听
前端·javascript·vue.js
xixixin_3 小时前
【Vite】前端开发服务器的配置
服务器·前端·网络
.生产的驴3 小时前
Vue3 加快页面加载速度 使用CDN外部库的加载 提升页面打开速度 服务器分发
运维·服务器·前端·vue.js·分布式·前端框架·vue
史迪仔01123 小时前
Python生成器:高效处理大数据的秘密武器
前端·数据库·python
蓝婷儿4 小时前
前端面试每日三题 - Day 34
前端·面试·职场和发展