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

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

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

在路由守卫处添加该代码

if(to.matched.length !== 0 ){
         next()
        //如果匹配到跳转下一页
     }else{
        //没有匹配到的话,跳转404
        next({path:'/404'})
   }

猜你喜欢

转载自www.cnblogs.com/zhanghongke/p/12655376.html
今日推荐