import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router'
import { getVersionFR } from '@/utils/version'
import layout from '@/components/layout/index.vue'
declare module 'vue-router' {
  interface RouteMeta {
    title?: string,
    transition?:any
  }
}
const routes: Array<RouteRecordRaw> = [
  {
    // 路由初始指向
    path: '/',
    name: 'redirect',
    component: layout,
    meta: {
      transition: 'van-fade'
    },
    redirect: 'home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home.vue'),
        meta: {
          transition: 'van-fade',
          title: '首页'
        }
      },
      {
        path: 'cate',
        name: 'cate',
        component: () => import('@/views/category.vue'),
        meta: {
          transition: 'van-fade',
          title: '分类'
        }
      },
      {
        path: 'search',
        name: 'search',
        component: () => import('@/views/search.vue'),
        meta: {
          transition: 'van-fade',
          title: '游戏搜索'
        }
      },
      {
        path: 'settings',
        name: 'settings',
        component: () => import('@/views/settings.vue'),
        meta: {
          transition: 'van-fade',
          title: '账号设置'
        }
      },
      {
        path: 'my_game',
        name: 'my_game',
        component: () => import('@/views/mine.vue'),
        meta: {
          transition: 'van-fade',
          title: '我的游戏'
        }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/order.vue'),
        meta: {
          transition: 'van-fade',
          title: '订单中心'
        }
      },
      {
        path: 'login',
        name: 'login',
        component: () => import('@/views/login.vue'),
        meta: {
          transition: 'van-fade',
          title: '登录'
        }
      },
      {
        path: 'coin_type1',
        name: 'coin_type1',
        component: () => import('@/views/ncoin.vue'),
        meta: {
          transition: 'van-fade',
          title: '我的余额'
        }
      },
      {
        path: 'coin_type2',
        name: 'coin_type2',
        component: () => import('@/views/ecoin.vue'),
        meta: {
          transition: 'van-fade',
          title: '我的余额'
        }
      }
    ]
  }
]
const router = createRouter({
  // createWebHashHistory hash 路由
  // createWebHistory history 路由
  // createMemoryHistory 带缓存 history 路由
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return { top: 0 }
  }
})

router.afterEach(() => {
  getVersionFR()
})

export default router
