{
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
}
});
vue3中路由错误自动跳转404页面 路由表写法
2024-06-14 10:48:07 23 阅读