import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Login from '@/views/login/index.vue'
import Home from '@/views/home/index.vue'
import Error from '@/views/404/index.vue'
import {getToken}  from '@/utils/token'
const routes: Array<RouteRecordRaw> = [
  {
    path:'/',
    redirect:'/login'
  },  
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    redirect:'/home/paybind',
    children:[
      {
        path: '/home/paybind',
        name: 'PayBind',
        component:  ()=>import('@/views/pay-bind/index.vue')
      },
      {
        path: '/home/payconfig',
        name: 'PayConfig',
        component:  ()=>import('@/views/pay-config/index.vue')
      },
      {
        path: '/home/goodscabinet',
        name: 'GoodsCabinet',
        component:  ()=>import('@/views/goods-cabinet/index.vue')
      },
      {
        path: '/home/paylist',
        name: 'PayList',
        component:  ()=>import('@/views/pay-list/index.vue')
      },
      {
        path: '/b',
        name: 'B',
        component:  ()=>import('@/views/B/index.vue')
      },
      
    ]
  },
  {
    path: '/404',
    name: '404',
    component: Error
  }
]
const router = createRouter({
  history: createWebHistory(),
  routes
})
// router.beforeEach((to,from,next)=>{
//   console.log(to,from,next,'to,from,next');
//   const token:any = getToken
//   if(token){
//     next()
//   }else{
//     next('/404')
//   }
 
// })
export default router
