美文网首页
vue3中设置404页面报错处理

vue3中设置404页面报错处理

作者: 新世界的冒险 | 来源:发表于2022-05-03 18:28 被阅读0次

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

image.png

设置404页面

在router/index.ts中

import { App } from 'vue';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
...
 {
   path: '*',
   component: () => import('@/views/error/404.vue')
 }
];
export const router = createRouter({
 history: createWebHistory(),
 routes
});

export const initRouter = (app: App<Element>) => {
 return app.use(router);
};

解决方法

在vue-router@4.x中写法不同
设置如下,即可正常访问

{
   path: '/:catchAll(.*)',
   component: () => import('@/views/error/404.vue')
 }

相关文章

网友评论

      本文标题:vue3中设置404页面报错处理

      本文链接:https://www.haomeiwen.com/subject/jxciyrtx.html