最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3輸入無效路由跳轉(zhuǎn)到指定error頁面問題

 更新時(shí)間:2024年03月06日 09:30:39   作者:小楊愛編程  
這篇文章主要介紹了vue3輸入無效路由跳轉(zhuǎn)到指定error頁面問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

開始準(zhǔn)備一個(gè)Error.vue展示錯(cuò)誤界面

<template>
<div class="border">
  <el-result
      icon="error"
      title="404,出錯(cuò)了!"
      sub-title="當(dāng)前地址無法解析,請返回!!!!!"
  >
    <template #extra>
      <el-button type="primary" @click="goBack">返回</el-button>
    </template>
  </el-result>
</div>
</template>
<script lang="ts" setup>
import {useRouter} from 'vue-router'
const router = useRouter()
const goBack = ()=>{
    router.push("/index")
}
 
</script>
 
<style scoped>
.border{
  width: 70%;
  height: 500px;
  background-color: white;
  border-radius: 10px;
  margin: 50px auto;
}
</style>

配置好Error,vue界面的路由

const routes = [
    //反饋界面
    { path: '/error', component: Error ,meta: {title: "出錯(cuò)了!當(dāng)前界面不存在"}},
    //首頁
    { path: '/index', component: Index,meta: {title: "首頁"}},
 
]
 
const router = VueRouter.createRouter({
    // 4. 內(nèi)部提供了 history 模式的實(shí)現(xiàn)。為了簡單起見,我們在這里使用 hash 模式。
    history: VueRouter.createWebHashHistory(),
    routes, // `routes: routes` 的縮寫
})
 
export default router

配置router.beforeEach

router.beforeEach((to, from, next) => {//beforeEach是router的鉤子函數(shù),在進(jìn)入路由前執(zhí)行
    if (to.matched.length === 0 ){
        next("/error")
    }
})

效果展示:

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

龙门县| 禹州市| 潜江市| 额敏县| 香河县| 新野县| 嘉兴市| 大丰市| 博野县| 金秀| 万山特区| 屏东县| 中山市| 开原市| 英德市| 卫辉市| 都兰县| 谢通门县| 天水市| 锦屏县| 晋州市| 兴国县| 蓬安县| 丘北县| 内黄县| 永宁县| 合作市| 丰原市| 苗栗县| 榕江县| 民县| 东兰县| 武威市| 兴宁市| 乐东| 洛南县| 芦山县| 龙川县| 普兰县| 永顺县| 隆子县|