import {createRouter,createWebHashHistory} from "vue-router";
import HomePage from '../views/home/Home'
import getToken from '@/request/token'
import { useGlobalState } from '@/store/index'

const state = useGlobalState()

export const defaultRoutes = [
  {
    path:'/',
    redirect: '/home/operationSupervision',
  },
  {
    path: '/home',
    name: 'HomePage',
    component: HomePage,
    children:[
      {
        path: 'trafficSafty',
        name: 'TrafficSafty',
        component: () => import('../views/jtaq/Index.vue')
      },
      {
        path: 'laneDredge',
        name: 'LaneDredge',
        component: () => import('../views/hdsj/Index.vue')
      },
      {
        path: 'operationSupervision',
        name: 'OperationSupervision',
        component: () => import('../views/yyjg/Index.vue')
      },
      {
        path: 'waterTransport',
        name: 'WaterTransport',
        component: () => import('../views/ssky/Index.vue')
      },
      {
        path: 'accessMonitor',
        name: 'AccessMonitor',
        component: () => import('../views/kkjk/Index.vue')
      },
    ]
  },
]


const router = createRouter({
  routes:defaultRoutes,
 
  history:createWebHashHistory()
 
})



router.beforeEach(async (to, from, next)=>{
  /* if(!state.token.value) {
    await getToken()
    next()
  } else {
    next()
  } */
  next()
})

export default router
