使用这种方式会报错

1
2
3
4
5
6
7
8
9
10
11
export const mainOutRoutes: AppRouteModule[] = [
{
path: '*', // 不识别的path自动匹配404
name: 'PageNotExist',
component: () => import('@/views/sys/exception/404.vue'),
meta: {
title: 'PageNotExist',
ignoreAuth: true
}
}
];

正确的方式

1
2
3
4
5
6
7
8
9
10
11
export const mainOutRoutes: AppRouteModule[] = [
{
path: '/:catchAll(.*)', // 不识别的path自动匹配404
name: 'PageNotExist',
component: () => import('@/views/sys/exception/404.vue'),
meta: {
title: 'PageNotExist',
ignoreAuth: true
}
}
];

或者

1
2
3
4
5
6
7
export const mainOutRoutes: AppRouteModule[] = [
{
path: '/:pathMatch(.*)',
name: '404',
component: () => import('@/views/404/index.vue')
}
];