vue router 怎么判断跳转空白页了?

vue router 怎么判断跳转的页面并没有这个路由存在?

 

我在全局前置导航守卫加了这个,不好使啊

router.beforeEach((to, from, next) => {
    if (to.matched.length === 0) {  //如果未匹配到路由
    // from.path ? next({ path: from.path }) : next('/');   //如果上级也未匹配到路由则跳转主页    面,如果上级能匹配到则转上级路由
    debugger;
  } else {
    next();    //如果匹配到正确跳转
 }
})

 

router.beforeEach((to,from,next) => {
   routerList.forEach(item => { // 这里的routerList 是你配置的路由表
    if (to.path !== item.path) {
        // 路由并不存在你的路由表中
    } else {
        // 存在
    }
   })
})

不知道是不是你说的这个东西

挺好用的啊,直接跳转就行了

if (to.matched.length === 0) {
    next('/404')
}