When we dynamically add routes, the router.addRouters() method reports an error: Uncaught (in promise) TypeError: router.default.addRouters is not a function.
Cause Analysis:
The new version of VueRouter abolishes addRoutes();//added array
Change to addRoute(RouteRecordRaw);//Added as an object
Solution:
// 旧版本写法
const routers = store.getters.addRouters;
router.addRoutes(routers);
// 新版本写法
const routers = store.getters.addRouters;
routers.forEach((route) => {
router.addRoute(route);
});
can solve the problem