import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/login' // 默认重定向到 /login
  },
  {
    path: '/init',
    name: 'Init',
    component: () => import('@/view/init/index.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/view/login/index.vue')
  },
  {
    path: '/user/register',
    name: 'Register',
    component: () => import('@/view/register/index.vue')
  },
  {
    path: '/registerSuccess',
    name: 'RegisterSuccess',
    beforeEnter: (to, from, next) => {
      // 检查是否从注册页面跳转过来
      if (from.name === 'Register') {
        next()
      } else {
        next({ name: 'Register' }) // 重定向到注册页面
      }
    },
    component: () => import('@/view/register/registerSuccess.vue')
  },
  {
    path: '/license',
    name: 'License',
    component: () => import('@/view/license/index.vue')
  },
  {
    path: '/:catchAll(.*)',
    meta: {
      closeTab: true
    },
    component: () => import('@/view/error/index.vue')
  }
]

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

export default router
