refactor(router): 优化路由配置和进度条逻辑

重构路由配置,统一使用双引号并调整缩进格式。优化进度条逻辑,确保首次加载时不触发统计,提升代码可读性和维护性。
This commit is contained in:
DESKTOP-RQ919RC\Pc 2025-03-31 11:17:12 +08:00
parent 9f041cd266
commit 9c303461a1
4 changed files with 162 additions and 159 deletions

2
dist/index.html vendored
View File

@ -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 () { ;(function () {
var hm = document.createElement("script") var hm = document.createElement("script")
hm.src = "//hm.baidu.com/hm.js?4bd66cbe45a640b607fe46c48f658746" hm.src = "//hm.baidu.com/hm.js?4bd66cbe45a640b607fe46c48f658746"

1
dist/js/app.ca821c63.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from "vue-router";
import HomeView from '../views/HomeView.vue' import HomeView from "../views/HomeView.vue";
import { setSeoTitle } from '@/utils/util.js' import { setSeoTitle } from "@/utils/util.js";
import store from '@/store' import store from "@/store";
//导入包 //导入包
import NProgress from "nprogress"; import NProgress from "nprogress";
import "nprogress/nprogress.css"; import "nprogress/nprogress.css";
@ -16,109 +16,112 @@ NProgress.configure({
const routes = [ const routes = [
{ {
path: '/', path: "/",
name: 'home', name: "home",
component: HomeView, component: HomeView,
meta: { meta: {
title: "首页", title: "首页",
path: '/', path: "/",
topBarShow: true topBarShow: true,
} },
}, },
{ {
path: '/about', path: "/about",
name: 'about', name: "about",
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') component: () => import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
}, { },
path: '/choosing-identity', {
name: 'choosing-identity', path: "/choosing-identity",
component: () => import(/* webpackChunkName: "choosing-identity" */ '@/views/choosing-identity.vue'), name: "choosing-identity",
component: () => import(/* webpackChunkName: "choosing-identity" */ "@/views/choosing-identity.vue"),
meta: { meta: {
title: "选择发布者身份" title: "选择发布者身份",
} },
}, },
{ {
path: '/edit', path: "/edit",
name: 'edit', name: "edit",
component: () => import(/* webpackChunkName: "edit" */ '@/views/edit.vue'), component: () => import(/* webpackChunkName: "edit" */ "@/views/edit.vue"),
meta: { meta: {
path: '/edit' path: "/edit",
} },
}, },
{ {
path: '/user', path: "/user",
name: 'user', name: "user",
component: () => import(/* webpackChunkName: "user" */ '@/views/user.vue'), component: () => import(/* webpackChunkName: "user" */ "@/views/user.vue"),
meta: { meta: {
title: "我的", title: "我的",
path: '/user', path: "/user",
topBarShow: true topBarShow: true,
} },
}, },
{ {
path: '/detail', path: "/detail",
name: 'detail', name: "detail",
component: () => import(/* webpackChunkName: "detail" */ '@/views/detail.vue'), component: () => import(/* webpackChunkName: "detail" */ "@/views/detail.vue"),
meta: { meta: {
title: "详情", title: "详情",
path: '/detail', 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'), path: "/personHousing",
component: () => import(/* webpackChunkName: "housing" */ "@/views/housingView/person.vue"),
meta: { meta: {
title: '中介房源', title: "个人房源",
path: '/intermediaryHousing', path: "/personHousing",
topBarShow: true 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'), path: "/intermediaryHousing",
component: () => import(/* webpackChunkName: "housing" */ "@/views/housingView/intermediary.vue"),
meta: { meta: {
title: '搜索', title: "中介房源",
path: '/seachPage' 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", path: "/apartment",
component: () => import(/* webpackChunkName: "housing" */ '@/views/housingView/apartment.vue'), component: () => import(/* webpackChunkName: "housing" */ "@/views/housingView/apartment.vue"),
meta: { meta: {
title: "品牌公寓", title: "品牌公寓",
path: '/apartment', path: "/apartment",
topBarShow: true topBarShow: true,
} },
}, },
{ {
path: "/apartmentDetail", path: "/apartmentDetail",
component: () => import(/* webpackChunkName: "housing" */ '@/views/apartmentDetail.vue'), component: () => import(/* webpackChunkName: "housing" */ "@/views/apartmentDetail.vue"),
meta: { meta: {
title: "品牌公寓详情", title: "品牌公寓详情",
path: '/apartmentDetail' path: "/apartmentDetail",
} },
} },
] ];
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
@ -128,10 +131,9 @@ const router = createRouter({
scrollBehavior(to, from, savedPosition) { scrollBehavior(to, from, savedPosition) {
return { top: 0 }; return { top: 0 };
}, },
}) });
let isInitialNavigation = false;
let isInitialNavigation = false
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
//进度条开始 //进度条开始
@ -139,15 +141,14 @@ router.beforeEach((to, from, next) => {
//随机增加进度 //随机增加进度
NProgress.inc(); NProgress.inc();
next();
next() let meta = to["meta"] || {};
let title = meta["title"];
let meta = to['meta'] || {} if (title) setSeoTitle(title);
let title = meta['title']
if (title) setSeoTitle(title)
if (isInitialNavigation) { if (isInitialNavigation) {
isInitialNavigation = false isInitialNavigation = false;
} else { } else {
// return // return
// console.log("1111111,", to.path, to.fullPath); // console.log("1111111,", to.path, to.fullPath);
@ -157,7 +158,6 @@ router.beforeEach((to, from, next) => {
// window._hmt.push(['_trackPageview', to.fullPath]) // window._hmt.push(['_trackPageview', to.fullPath])
// } // }
// } // }
// if (window._czc) { // if (window._czc) {
// let location = window.location // let location = window.location
// let contentUrl = location.pathname + location.hash // let contentUrl = location.pathname + location.hash
@ -166,11 +166,14 @@ router.beforeEach((to, from, next) => {
// window._czc.push(["_trackPageview", contentUrl, refererUrl]) // window._czc.push(["_trackPageview", contentUrl, refererUrl])
// } // }
} }
}) });
// 判断是不是首次 加载
let isInitialNavigation2 = true;
router.afterEach(() => { router.afterEach(() => {
NProgress.done(true); NProgress.done(true);
if (isInitialNavigation2) isInitialNavigation2 = false;
XSTAT.trackNewPage() else XSTAT && XSTAT.trackNewPage();
}) });
export default router export default router;