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

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: () => import('@/views/Home.vue'),
      meta: { title: '首页' }
    },
    {
      path: '/demand',
      name: 'TaskDemand',
      component: () => import('@/views/TaskDemand.vue'),
      meta: { title: '任务需求' }
    },
    {
      path: '/search',
      name: 'TaskSearch',
      component: () => import('@/views/TaskSearch.vue'),
      meta: { title: '任务检索' }
    },
    {
      path: '/input/:id?',
      name: 'TaskInput',
      component: () => import('@/views/TaskInput.vue'),
      meta: { title: '任务需求信息录入' }
    },
    {
      path: '/statistics',
      name: 'Statistics',
      component: () => import('@/views/Statistics.vue'),
      meta: { title: '统计分析' }
    },
    {
      path: '/contact',
      name: 'Contact',
      component: () => import('@/views/Contact.vue'),
      meta: { title: '联系我们' }
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = '应急搜捞 - ' + to.meta.title
  }
  next()
})

export default router
