import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import Layout from "@/layout/index.vue";
const router = createRouter({
  history: createWebHashHistory("/carstop/dist6"), // 线上地址
  // history: createWebHashHistory("/testingServertomcat/dist6"), // 测试环境发布地址
  routes: [
    {
      path: "/login",
      component: () => import("@/views/login/index.vue"),
    },
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/schoolBus",
      component: Layout,
      children: [
        {
          path: "news",
          component: () => import("@/views/news/news.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "statement",
          component: () => import("@/views/statement/statement.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "staff",
          component: () => import("@/views/staff/staff.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "account",
          component: () => import("@/views/account/account.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "bus",
          component: () => import("@/views/bus/bus.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "classes",
          component: () => import("@/views/classes/classes.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "buspath",
          component: () => import("@/views/buspath/buspath.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "blacklist",
          component: () => import("@/views/blacklist/blacklist.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "system",
          component: () => import("@/views/waiting/waiting.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "busquery",
          component: () => import("@/views/busquery/busquery.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "log",
          component: () => import("@/views/log/log.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "report",
          component: () => import("@/views/report/report.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
      ],
    },
  ],
});
export default router;
router.beforeEach((to, from, next) => {
  // 判断 如果cook是否存在，可以进去
  if (sessionStorage.getItem("token")) {
    next(); //放行
  } else {
    if (to.path == "/login") {
      next();
    } else {
      next(`/login`);
    }
  }
});
