手写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>

页面显示如下

相关推荐
小圣贤君12 小时前
在 Electron 应用中优雅接入 DeepSeek AI:从零到一的完整实践指南
人工智能·electron·vue3·ai写作·deepseek
Sapphire~1 天前
Vue3-14 watch监视对象及对象属性,watchEffect
vue3
技术宅星云1 天前
7. vue3-element-admin 二次开发图文教程
vue3·element-admin·后端开箱即用前端框架
Sheldon一蓑烟雨任平生2 天前
Sass 星空(Sass + keyframes 实现星空动画)
前端·css·vue3·sass·keyframes
Irene19913 天前
Vue 3 中移除了 $on、$off 和 $once 方法(附:Composables 组合式函数 使用详解)
vue3
wuhen_n4 天前
Webpack vs Vite:前端构建工具对比
前端·webpack·node.js·vite
Sapphire~4 天前
Vue3-15 html标签和组件上的ref属性 + 接口泛型
vue3
Irene19914 天前
Vue 3 中使用 Mitt 事件总线
vue3·mitt
咸甜适中5 天前
双色球、大乐透兑奖分析小程序(rust_Tauri + Vue3 + sqlite)
爬虫·rust·sqlite·vue3·tauri2
Sapphire~6 天前
Vue3-012 vue2与vue3中的computed
vue3