前端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
相关推荐
炫饭第一名2 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
王晓枫3 小时前
flutter接入三方库运行报错:Error running pod install
前端·flutter
符方昊3 小时前
React 19 对比 React 16 新特性解析
前端·react.js
ssshooter3 小时前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?
前端
曲折3 小时前
Cesium-气象要素PNG色斑图叠加
前端·cesium
Forever7_3 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
Angelial3 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
jiayu4 小时前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套
前端
jiayu4 小时前
Angular6学习笔记13:HTTP(3)
前端
小码哥_常4 小时前
Kotlin抽象类与接口:相爱相杀的编程“CP”
前端