import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import {getToken} from  "@/utils/token"
import Login from '@/views/login/index.vue'
import Home from '@/views/home/index.vue'
import Error from '@/views/404/index.vue'
import { onGetRouter } from '@/utils/userInfo'
console.log(onGetRouter(),'getRouter');

const routes: Array<RouteRecordRaw> = [
  {
    path:'/',
    redirect:'/login'
  },  
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    redirect:'/home/paybind',
  },
  {
    path: '/404',
    name: '404',
    component: Error
  }
]
const router = createRouter({
  history: createWebHistory(),
  routes
})
router.beforeEach((to,from,next)=>{
  const token:any = getToken
  if(token){
    next()
  }else{
    router.push('/login')
  }
})
export default router


// {"id":1,"name":"支付配置","sort":2,"path":"/home","component": ()=>import('@/views/home/page/index.vue'),meta:{ iconfont:'icon-fencengpeizhi'},redirect:'/home/page/paybind',children:[{path: '/home/page/paybind',name: 'PayBind',component:  ()=>import('@/views/home/page/pay-bind/index.vue')},{path: '/home/page/payconfig', name: 'PayConfig', component:  ()=>import('@/views/home/page/pay-config/index.vue')}, ]}
