132 lines
3.0 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-04-17 19:24:06 +08:00
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-04-18 16:44:14 +08:00
// mode: 'history',
// mode: 'hash',
mode: process.env.NODE_ENV == "development" ? 'hash' : 'history',
2023-03-28 18:04:49 +08:00
base: process.env.BASE_URL,
routes
})
router.beforeEach(async (to, from, next) => {
if (to.meta.title) document.title = getPageTitle(to.meta.title);
2023-07-07 11:04:32 +08:00
var _hmt = _hmt || [];
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?4bd66cbe45a640b607fe46c48f658746";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
var _hmt1 = _hmt1 || [];
var hm1 = document.createElement("script");
hm1.src = "//v1.cnzz.com/z_stat.php?id=1281224882&web_id=1281224882";
var s1 = document.getElementsByTagName("script")[0];
s1.parentNode.insertBefore(hm1, s1);
2023-03-28 18:04:49 +08:00
next();
});
export default router