import { getAuth } from '@/helpers/utils'
import { getUserInfo } from '@/state'
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
  Router
} from 'vue-router'
import routes from './routes-admin'
const router: Router = createRouter({
  // history: createWebHistory('/website'),
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    return new Promise((resolve, reject) => {
      resolve({ left: 0, top: 0 })
    })
  }
})

router.beforeEach(async (to, from, next) => {
  const title = to.meta.title
  // document.title = (title || '酷乐秀') as any
  // 备案要求，title名称必须和备案名称一致
  document.title = '酷乐秀'
  try {
    // 获取用户信息
    await getUserInfo()
  } catch {}
  next()
})

export default router
