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 




















