自定义404
页面
当我们访问一个地址的时候,如果该地址没有定义匹配的路由,我们需要给他显示一个404
页面,即表示页面找不到
我们首先需要定义一个404
页面,比如errorPage.vue
:
vue
<template>
error
</template>
<script setup>
</script>
<style lang="scss" scoped>
</style>
在路由文文件中进行添加:
js
{
path: '/:pathMatch(.*)*', // pathMatch可以写任意的内容,写any也是常见的
name: 'errorpage', // name可以不要
component: () => import('@/pages/ErrorPage.vue'),
}