手写VUE后台管理系统8 - 配置404NotFound路由

设置404页面


配置路由

这里配置了两个路由,一个是主页,另外一个则匹配任意路由显示为404页面。因为只配置了两个路由,如果路径没有匹配到主页,则会被自动导向到404页面,这样就可以实现整站统一的404页面。

ts 复制代码
import { RouteRecordRaw } from "vue-router"

const routes: RouteRecordRaw[] = [{
    name: "Home",
    path: '/',
    component: () => import('@/views/dashboard/home/Index.vue')
}, {
    path: '/:pathMatch(.*)',
    component: () => import('@/views/exception/404.vue')
}]

export default routes

404页面

使用 ant 提供的组件实现 404 页面

html 复制代码
<template>
    <a-result status="404" title="404" sub-title="页面不存在">
        <template #extra>
            <a-button type="primary">返回首页</a-button>
        </template>
    </a-result>
</template>

页面显示如下

相关推荐
Sapphire~2 天前
Vue3-11 toRefs 和 toRef
vue3
zhengxianyi5152 天前
vite build 发布到nginx二级目录——将yudao-ui-go-view打包、部署到big目录下
vue.js·nginx·vite·前后端分离·打包·ruoyi-vue-pro优化·部署运维
Mast Sail2 天前
WebStrom+Vitesse+Vue3项目路径报错爆红问题
vue·vite·webstorm
华玥作者3 天前
uni-app + Vite 项目中使用 @uni-helper/vite-plugin-uni-pages 实现自动路由配置(超详细)
前端·uni-app·vue·vue3·vite
麷飞花4 天前
TypeScript问题
前端·javascript·vscode·typescript·ts
独立开发者阿乐4 天前
Vue3中Markdown解析与渲染的完整解决方案:从安全到性能优化
web安全·性能优化·vue3·前端开发·语法高亮·markdown解析·markdown-it
Sapphire~5 天前
Vue3-10 ref与reactive创建响应式数据的区别
vue3
Irene19916 天前
Vue3 TypeScript 项目中,Emits 验证的使用场景
typescript·vue3·验证
箫笙默6 天前
Vue3基础笔记
笔记·vue·vue3
Sapphire~6 天前
Vue3-09 创建响应式数据(基本类型ref和对象类型reactive)
vue3