refactor(router): 优化路由配置和进度条逻辑
重构路由配置,统一使用双引号并调整缩进格式。优化进度条逻辑,确保首次加载时不触发统计,提升代码可读性和维护性。
This commit is contained in:
parent
9f041cd266
commit
9c303461a1
2
dist/index.html
vendored
2
dist/index.html
vendored
@ -1,4 +1,4 @@
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/favicon.ico"/><title>港校租房</title><script defer="defer" src="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/js/chunk-vendors.6d96b969.js"></script><script defer="defer" src="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/js/app.e2006f78.js"></script><link href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/css/chunk-vendors.7885d77e.css" rel="stylesheet"><link href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/css/app.5341a9f0.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but zufang doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><script src="https://app.gter.net/bottom?tpl=header&menukey=fang"></script><div id="app"></div><div style="display: none;"><script>var _hmt = _hmt || []
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/favicon.ico"/><title>港校租房</title><script defer="defer" src="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/js/chunk-vendors.6d96b969.js"></script><script defer="defer" src="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/js/app.ca821c63.js"></script><link href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/css/chunk-vendors.7885d77e.css" rel="stylesheet"><link href="https://ansnid.oss-cn-shenzhen.aliyuncs.com/fang/css/app.5341a9f0.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but zufang doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><script src="https://app.gter.net/bottom?tpl=header&menukey=fang"></script><div id="app"></div><div style="display: none;"><script>var _hmt = _hmt || []
|
||||
;(function () {
|
||||
var hm = document.createElement("script")
|
||||
hm.src = "//hm.baidu.com/hm.js?4bd66cbe45a640b607fe46c48f658746"
|
||||
|
1
dist/js/app.ca821c63.js
vendored
Normal file
1
dist/js/app.ca821c63.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/js/app.e2006f78.js
vendored
1
dist/js/app.e2006f78.js
vendored
File diff suppressed because one or more lines are too long
@ -1,176 +1,179 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import HomeView from '../views/HomeView.vue'
|
||||
import { setSeoTitle } from '@/utils/util.js'
|
||||
import store from '@/store'
|
||||
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, // 初始化时的最小百分比
|
||||
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'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
{
|
||||
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(),
|
||||
// history: createWebHistory(),
|
||||
mode: "history",
|
||||
routes,
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
return { top: 0 };
|
||||
},
|
||||
})
|
||||
history: createWebHistory(),
|
||||
// history: createWebHistory(),
|
||||
mode: "history",
|
||||
routes,
|
||||
scrollBehavior(to, from, savedPosition) {
|
||||
return { top: 0 };
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
let isInitialNavigation = false
|
||||
let isInitialNavigation = false;
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
//进度条开始
|
||||
NProgress.start();
|
||||
//随机增加进度
|
||||
NProgress.inc();
|
||||
//进度条开始
|
||||
NProgress.start();
|
||||
//随机增加进度
|
||||
NProgress.inc();
|
||||
|
||||
next();
|
||||
|
||||
next()
|
||||
let meta = to["meta"] || {};
|
||||
let title = meta["title"];
|
||||
if (title) setSeoTitle(title);
|
||||
|
||||
let meta = to['meta'] || {}
|
||||
let title = meta['title']
|
||||
if (title) setSeoTitle(title)
|
||||
if (isInitialNavigation) {
|
||||
isInitialNavigation = false;
|
||||
} else {
|
||||
// return
|
||||
// console.log("1111111,", to.path, to.fullPath);
|
||||
// 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])
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
if (isInitialNavigation) {
|
||||
isInitialNavigation = false
|
||||
} else {
|
||||
// return
|
||||
// console.log("1111111,", to.path, to.fullPath);
|
||||
// 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])
|
||||
// }
|
||||
}
|
||||
})
|
||||
// 判断是不是首次 加载
|
||||
let isInitialNavigation2 = true;
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done(true);
|
||||
|
||||
XSTAT.trackNewPage()
|
||||
})
|
||||
export default router
|
||||
NProgress.done(true);
|
||||
if (isInitialNavigation2) isInitialNavigation2 = false;
|
||||
else XSTAT && XSTAT.trackNewPage();
|
||||
});
|
||||
export default router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user