router.addRouters()方法報(bào)錯(cuò)
Uncaught (in promise) TypeError: router__WEBPACK_IMPORTED_MODULE_2_.default.addRouters is not a function
原因:
新版VueRouter廢除了addRoutes();//添加的數(shù)組
改為addRoute(RouteRecordRaw);//添加的為對(duì)象
原代碼為:
const routers = store.getters.addRouters;
router.addRoutes(routers);
改為:
const routers = store.getters.addRouters;
routers.forEach((route) => {
router.addRoute(route);
});
即可解決。
404正則匹配
Uncaught (in promise) Error: Catch all routes ("*") must now be defined using a param with a custom regexp.
原因:
vue3對(duì)404配置進(jìn)行了修改,必須要使用正則匹配
{
// 匹配所有路徑 vue2使用* vue3使用/:pathMatch(.*)*或/:pathMatch(.*)或/:catchAll(.*)
path: "/:catchAll(.*)*",
name: "404",
component: ()=> import("../components/NoFind.vue")
}