import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/HomeView.vue' import { setSeoTitle } from '@/utils/util.js' import store from '@/store' //导入包 import NProgress from "nprogress"; import "nprogress/nprogress.css"; NProgress.configure({ easing: "ease", // 动画方式 speed: 1500, // 递增进度条的速度 showSpinner: false, // 是否显示加载ico trickleSpeed: 800, // 自动递增间隔 minimum: 0.9, // 初始化时的最小百分比 }); const routes = [ { path: '/', name: 'home', component: HomeView, meta: { title: "首页", path: '/', topBarShow: true } }, { 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'), meta: { path: '/edit' } }, { path: '/user', name: 'user', component: () => import(/* webpackChunkName: "user" */ '@/views/user.vue'), meta: { title: "我的", path: '/user', topBarShow: true } }, { path: '/detail', name: 'detail', component: () => import(/* webpackChunkName: "detail" */ '@/views/detail.vue'), meta: { title: "详情", path: '/detail', } }, {//个人房源 path: '/personHousing', component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/person.vue'), meta: { title: '个人房源', path: '/personHousing', topBarShow: true } }, {//中介房源 path: '/intermediaryHousing', component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/intermediary.vue'), meta: { title: '中介房源', path: '/intermediaryHousing', topBarShow: true } }, {//求房源 path: '/needHousing', component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/needHousing.vue'), meta: { title: '求房源', path: '/needHousing', topBarShow: true } }, {//搜索 path: '/seachPage/:type?/:data?/:areaItem?/:types?', component: () => import(/* webpackChunkName: "seachPage" */ '@/views/seachIndex.vue'), meta: { title: '搜索', path: '/seachPage' } }, { path: "/apartment", component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/apartment.vue'), meta: { title: "品牌公寓", path: '/apartment', topBarShow: true } }, { path: "/apartmentDetail", component: () => import(/* webpackChunkName: "housing" */ '@/views/apartmentDetail.vue'), meta: { title: "品牌公寓详情", path: '/apartmentDetail' } } ] const router = createRouter({ history: createWebHistory(process.env.BASE_URL), mode: "history", routes, scrollBehavior(to, from, savedPosition) { return { top: 0 }; }, }) router.beforeEach((to, from, next) => { //进度条开始 NProgress.start(); //随机增加进度 NProgress.inc(); next() let meta = to['meta'] || {} let title = meta['title'] if (title) setSeoTitle(title) if (window._hmt) { if (to.path) { // window._hmt.push(['_trackPageview', '/#' + to.fullPath]) window._hmt.push(['_trackPageview', to.fullPath]) } } if (window._czc) { let location = window.location let contentUrl = location.pathname + location.hash let refererUrl = "/" // 用于发送某个URL的PV统计请求 window._czc.push(["_trackPageview", contentUrl, refererUrl]) } }) router.afterEach(() => { NProgress.done(true); }) export default router