使用router.push的name属性调转时无法匹配404页面

首先要路由的最后插入404组件

//前面已定以404组件,这里作转发
    let router404 = {
          path:'*',
          redirect:'/404',
          hidden:true
    }

在路由守卫处添加该代码

if(to.matched.length !== 0 ){
         next()
        //如果匹配到跳转下一页
     }else{
        //没有匹配到的话,跳转404
        next({path:'/404'})
   }
posted @ 2020-04-07 19:02  悟空等待唐僧的日子  阅读(668)  评论(0编辑  收藏  举报