import { createRouter, createWebHistory } from "vue-router";
import useStore from "@/store";
import { setGuard } from '@/router/guard';
import { constRoutes } from '@/router/route'



// 创建路由
const router = createRouter({
  history: createWebHistory("/wms-sap/"),
  routes: constRoutes as [],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 重置路由
export function resetRouter() {
  const { app } = useStore();
  app.routes.forEach((route: any) => {
    const name = route.name;
    if (name && router.hasRoute(name)) {
      router.removeRoute(name);
    }
  });
}

// 执行路由守卫
setGuard(router);

export default router;
