import { createRouter, createWebHistory } from "vue-router";

// 自动导入所有模块路由
const modules = import.meta.glob('./modules/*.js', { eager: true })

const fileRoutes = Object.keys(modules).reduce((acc, path) => {
  const module = modules[path].default
  acc.push(...module)
  return acc
}, [])

const routes = [
  ...fileRoutes,
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    // document.title = `${to.meta.title} - Think Tank`
  }
  next();
});

export default router;
