Skip to content

Commit cc1d2b1

Browse files
author
preschool
committed
🎈 perf:优化动态路由在首次加载时未匹配导致警告、路由不存在时保留错误路径
1 parent 5a21c0e commit cc1d2b1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/router/modules/remaining.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@ const remainingRouter: AppRouteRecordRaw[] = [
593593
}
594594
}
595595
]
596+
},
597+
{
598+
path: '/:pathMatch(.*)*',
599+
component: () => import('@/views/Error/404.vue'),
600+
name: '',
601+
meta: {
602+
title: '404',
603+
hidden: true,
604+
breadcrumb: false
605+
}
596606
}
597607
]
598608

src/store/modules/permission.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ export const usePermissionStore = defineStore('permission', {
4040
}
4141
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
4242
// 动态路由,404一定要放到最后面
43+
// preschooler:vue-router@4以后已支持静态404路由,此处可不再追加
4344
this.addRouters = routerMap.concat([
4445
{
4546
path: '/:path(.*)*',
46-
redirect: '/404',
47+
// redirect: '/404',
48+
component: () => import('@/views/Error/404.vue'),
4749
name: '404Page',
4850
meta: {
4951
hidden: true,

0 commit comments

Comments
 (0)