如果用户访问的是没有页面的路由跳转到404

  {
    path: '/:catchAll(.*)',
    name: 'NotFound',
    hidden: true,
    component: () => import('@/views/notFound/not-found.vue'),
  }
router.beforeEach((to, from, next) => {
  const isValidRoute = router.options.routes.some(route => route.path === to.path);
  if (isValidRoute) {
    next(); // Route exists, continue navigating to the target route
  } else {
    next({ name: 'NotFound' }); // Route does not exist, redirect to the 404 page or other error page
  }
});

最近更新

  1. TCP协议是安全的吗?

    2024-06-14 10:48:07       17 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-14 10:48:07       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-14 10:48:07       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-14 10:48:07       18 阅读

热门阅读

  1. Spring源码学习-Resource

    2024-06-14 10:48:07       7 阅读
  2. 行列视(RCV)能解决哪些问题?

    2024-06-14 10:48:07       7 阅读
  3. easyExcel导入日期LocalDateTime等类型不匹配问题

    2024-06-14 10:48:07       7 阅读
  4. milvus的磁盘索引

    2024-06-14 10:48:07       8 阅读
  5. npm发布自己的插件包

    2024-06-14 10:48:07       7 阅读
  6. redis的分布式session和本地的session有啥区别

    2024-06-14 10:48:07       8 阅读
  7. postgresql中geometry类型数据迁移

    2024-06-14 10:48:07       9 阅读
  8. 小程序的价值是什么?

    2024-06-14 10:48:07       9 阅读
  9. 树的经典问题和方法

    2024-06-14 10:48:07       7 阅读
  10. 记录一次网络延迟的事件分析

    2024-06-14 10:48:07       10 阅读