首先要路由的最后插入404组件
//前面已定以404组件,这里作转发 let router404 = { path:'*', redirect:'/404', hidden:true }
在路由守卫处添加该代码
if(to.matched.length !== 0 ){ next() //如果匹配到跳转下一页 }else{ //没有匹配到的话,跳转404 next({path:'/404'}) }
//前面已定以404组件,这里作转发 let router404 = { path:'*', redirect:'/404', hidden:true }
if(to.matched.length !== 0 ){ next() //如果匹配到跳转下一页 }else{ //没有匹配到的话,跳转404 next({path:'/404'}) }