import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/Layout/index.vue'
import { getRouters } from '../pages';
// history: createWebHistory(import.meta.env.BASE_URL),
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: []
  },
  {
    path: '/login',
    name: '/login',
    component: () => import('@/views/Login/index.vue')
  }
];

const pages = getRouters();
//动态添加路由
routes[0].children.push(...pages);

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  //@test
  if (to.matched.length === 0) {
    // 页面不存在，说明是刷新事件
    // 在此处执行您需要的操作
    //console.log('111')
  }
  next()
})

export default router
