当路由出现问题时,如何通过路由进入自定义的404页面

在main.j中使用全局前置守卫 router.beforeEach来检测路由

import router from './router'

//....

router.beforeEach((to, from, next) => {
  if (to.matched.length === 0) {
    next('/404')
  } else {
    next()
  }
});

这里还可以用来初步判断是否登录之类的,登录与否进入页面不同
原文地址:https://www.cnblogs.com/aidixie/p/12620922.html