Error: Catch all routes ("*") must now be defined using a param with a custom regexp.

router/index.ts:
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
redirect: '/home',
},
{
path: '/index/home',
component: () => import('../views/index/Home.vue'),
},
{
path: '/home',
component: () => import('../views/home/Index.vue'),
},
{
path: '/me',
component: () => import('../views/me/Index.vue'),
sensitive: true
},
{
path: '/404',
component: () => import('../views/notFound/Index.vue')
},
{
path: '*',
redirect: '/404'
}
],
})
router.beforeEach((to, from) => {
return true
})
export default router
解决方案:
router/index.ts:
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
redirect: '/home',
},
{
path: '/index/home',
component: () => import('../views/index/Home.vue'),
},
{
path: '/home',
component: () => import('../views/home/Index.vue'),
},
{
path: '/me',
component: () => import('../views/me/Index.vue'),
sensitive: true
},
{
path: '/404',
component: () => import('../views/notFound/Index.vue')
},
{
path: '/:catchAll(.*)',
redirect: '/404'
}
],
})
router.beforeEach((to, from) => {
return true
})
export default router
参考链接:
https://blog.csdn.net/chaoPerson/article/details/135893350
人工智能学习网站
151

被折叠的 条评论
为什么被折叠?



