初始路由如下
const routes = [
{
path: "/login",
name: "Login",
component: () => import("@/views/Login.vue"),
},
{
path: "/layout",
name: "Layout",
component: () => import("@/layout/AppMain.vue"),
children: [
{
path: "/401",
name: "401",
component: () => import("@/views/error/401.vue"),
icon: "",
},
{
path: "/404",
name: "404",
component: () => import("@/views/error/404.vue"),
},
],
},
];
动态添加的路由
const routeObj = {
path: "/layout/test", // 这里用layout/test,/test, test都是一样的结果
name: "test",
meta: { title: "测试路由test", noCache: true },
component: () => import("@/views/error/404.vue"),
};
router.addRoute(routeObj);或者router.addRoute('Layout', routeObj)一样不能添加到Layout子路由中
请大神解惑
把layout路由也作为动态来添加,再把layout/test作为children,再addRoute