import { createRouter, createWebHistory } from 'vue-router'
import { dynamicRoutes} from './menuArr'

const first = dynamicRoutes('first')
const second=dynamicRoutes('second');
const third=dynamicRoutes('third');
// const menuArr=second;
const menuArr=first.concat(second).concat(third);

console.log("路由里面的menuArr",menuArr)

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      meta: {
        title: 'layout'
      },
      redirect: "dashboard",
      component: () => import('@/views/LayoutView.vue'),
      children: menuArr,
    },
     {
      path: "/login",
      name: "login",
      component: () => import('@/views/login/index.vue'),
      meta: {
        title: '登录'
      }
    },
    {
      path:'/userInfo',
      name:'userInfo',
      component:()=>import('@/views/userInfo.vue'),
      meta:{
        title:'userInfo'
      }

    },
  ]
})
// // 动态添加路由的函数
// // 动态添加路由的函数
// function addDynamicRoutes(newMenuArr) {
//   // 解析并移除旧的 'layout' 路由
//   const layoutRoute = router.resolve({ name: 'layout' }).route;
//   router.removeRoute(layoutRoute.name);



//   const routesToRemove = router.getRoutes().filter(route => route.path === routePath);
//   routesToRemove.forEach(route => {
//     router.removeRoute(route.path);
//   });
//   // 添加新的 'layout' 路由
//   router.addRoute({
//     path: '/',
//     name: 'layout',
//     meta: {
//       title: 'layout'
//     },
//     redirect: "dashboard",
//     component: () => import('@/views/LayoutView.vue'),
//     children: newMenuArr,
//   });
// }

export default router
export { menuArr }
