import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { setSeoTitle } from '@/utils/util.js'
import store from '@/store'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    meta: {
      title: "首页"
    }
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }, {
    path: '/choosing-identity',
    name: 'choosing-identity',
    component: () => import(/* webpackChunkName: "choosing-identity" */ '@/views/choosing-identity.vue'),
    meta: {
      title: "选择发布者身份"
    }
  },
  {
    path: '/edit',
    name: 'edit',
    component: () => import(/* webpackChunkName: "edit" */ '@/views/edit.vue'),
  },
  {
    path: '/user',
    name: 'user',
    component: () => import(/* webpackChunkName: "user" */ '@/views/user.vue'),
    meta: {
      title: "我的"
    }
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import(/* webpackChunkName: "detail" */ '@/views/detail.vue'),
    meta: {
      title: "详情"
    }
  },
  {//个人房源
    path: '/personHousing',
    component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/person.vue'),
    meta: {
      title: '个人房源'
    }
  },
  {//中介房源
    path: '/intermediaryHousing',
    component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/intermediary.vue'),
    meta: {
      title: '中介房源'
    }
  },
  {//求房源
    path: '/needHousing',
    component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/needHousing.vue'),
    meta: {
      title: '求房源'
    }
  },
  {//搜索
    path: '/seachPage',
    component: () => import(/* webpackChunkName: "seachPage" */ '@/views/seachIndex.vue'),
    meta: {
      title: '搜索'
    }
  },
  {
    path: "/apartment",
    component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/apartment.vue'),
    meta: {
      title: "品牌公寓"
    }
  },
  {
    path: "/apartmentDetail",
    component: () => import(/* webpackChunkName: "housing" */ '@/views/apartmentDetail.vue'),
    meta: {
      title: "品牌公寓详情"
    }
  }
]


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  mode: "history",
  routes
})


router.beforeEach((to, from, next) => {
  // <<<<<<< HEAD
  //导航数据
  if (/['seachPage','needHousing','intermediaryHousing','personHousing']/.test(from.path)) {
    store.state.routeList.secondaryIndex.title = from.meta.title
    store.state.routeList.secondaryIndex.path = from.path
  }
  // >>>>>>> 542e853 (提交)
  next()
  let meta = to['meta'] || {}
  let title = meta['title']
  if (title) setSeoTitle(title)
})

export default router
