import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/Home.vue'
import UnitList from '../views/UnitList.vue'
import RelicList from '../views/RelicList.vue'
import RelicDetail from '../views/RelicDetail.vue'
// import store from '@/store/index.js'

const routes = [
  {
    path: '/',
    name: 'HomeView',
    component: HomeView,
  },
  {
    path: '/unit-list',
    name: 'UnitList',
    component: UnitList,
  },
  {
    path: '/relic-list',
    name: 'RelicList',
    component: RelicList,
  },
  {
    path: '/relic-detail',
    name: 'RelicDetail',
    component: RelicDetail,
  },
]

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

router.beforeEach((to, from) => {
  // 生产环境下强制每次都从首页进入
  if (process.env.NODE_ENV === 'production' && !from.name && to.name !== 'HomeView') {
    return '/'
  }
})

export default router
