143 lines
3.1 KiB
JavaScript
Raw Normal View History

2023-03-28 18:04:49 +08:00
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err)
}
2023-04-18 16:44:14 +08:00
2023-03-28 18:04:49 +08:00
//标题js
import getPageTitle from "@/utils/title-config";
const Index = () => import('views/index/index')
const Recommend = () => import('views/index/recommend/Recommend')
const Collect = () => import('views/index/collect/Collect')
const AllSections = () => import('views/index/allSections/AllSections')
const search = () => import('views/search/search')
const SearchResult = () => import('views/search/searchResult/SearchResult')
const user = () => import('views/user/user')
const userIndex = () => import('views/user/UserIndex')
const detail = () => import('views/detail/detail')
const detailIndex = () => import('views/detail/detailIndex')
2023-03-28 18:04:49 +08:00
const routes = [
{
// 首页
2023-10-16 17:26:27 +08:00
// path: '*',
path: '/',
2023-03-28 18:04:49 +08:00
name: 'Index',
redirect: "/recommend",
component: Index,
children: [
{
path: '/recommend',
name: 'Recommend',
component: Recommend,
meta: {
title: "推荐版块"
}
},
{
path: '/collect',
name: 'Collect',
component: Collect,
meta: {
title: "收藏的版块"
}
},
{
path: '/allSections',
name: 'AllSections',
component: AllSections,
meta: {
title: "全部版块"
}
},
]
}, {
path: '/searchResult', // 搜索结果
name: 'search',
redirect: "/searchResult",
component: search,
children: [
{
path: '/searchResult',
name: 'Recommend',
component: SearchResult,
meta: {
title: "搜索帖子"
}
},
2023-03-28 18:04:49 +08:00
]
}, {
path: '/user', // 我的
name: 'user',
redirect: "/userIndex",
component: user,
children: [
{
path: '/userIndex',
name: 'userIndex',
component: userIndex,
meta: {
title: "我的寄托"
}
},
]
}, {
path: '/detail', // 帖子详情
name: 'detail',
redirect: "/detailIndex",
component: detail,
children: [
{
path: '/detailIndex',
name: 'detailIndex',
component: detailIndex,
meta: {
title: "帖子详情"
}
},
]
}
2023-03-28 18:04:49 +08:00
]
const router = new VueRouter({
2023-10-16 17:26:27 +08:00
mode: 'history',
2023-04-18 16:44:14 +08:00
// mode: 'hash',
2023-10-16 17:26:27 +08:00
// mode: process.env.NODE_ENV == "development" ? 'hash' : 'history',
2023-10-16 17:03:34 +08:00
// base: process.env.BASE_URL,
2023-03-28 18:04:49 +08:00
routes
})
2023-12-18 11:08:45 +08:00
let isInitialNavigation = true
2023-03-28 18:04:49 +08:00
router.beforeEach(async (to, from, next) => {
if (to.meta.title) document.title = getPageTitle(to.meta.title);
2023-12-18 11:08:45 +08:00
if (isInitialNavigation) {
isInitialNavigation = false
} else {
if (window._hmt) {
if (to.path) {
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])
2023-07-07 11:20:30 +08:00
}
2023-07-07 11:04:32 +08:00
2023-07-07 11:20:30 +08:00
}
2023-07-07 11:04:32 +08:00
2023-03-28 18:04:49 +08:00
next();
});
export default router