78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
import { reactive, onMounted, onBeforeUnmount } from 'vue'
|
|
|
|
|
|
import HomePage from './HomePage.vue'
|
|
import ShouFei from './ShouFei.vue'
|
|
import KeFu from './KeFu.vue'
|
|
import ZhengShu from './ZhengShu.vue'
|
|
import DaiLiShang from './DaiLiShang.vue'
|
|
import HelpCenter from './HelpCenter.vue'
|
|
import TransactionCenter from './TransactionCenter.vue'
|
|
import AboutUs from './AboutUs.vue'
|
|
import Report from './Report.vue'
|
|
import ProductsNews from './ProductsNews.vue'
|
|
import MobilePage from './MobilePage.vue'
|
|
import isMobile from './isMobile'
|
|
|
|
|
|
// 调用createRouter方法
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes: [
|
|
{ path: '/', redirect: '/HomePage' },
|
|
{ path: '/HomePage', name: 'HomePage', component: HomePage },
|
|
{ path: '/ShouFei', name: 'ShouFei', component: ShouFei },
|
|
{ path: '/KeFu', name: 'KeFu', component: KeFu },
|
|
{ path: '/ZhengShu', name: 'ZhengShu', component: ZhengShu },
|
|
{ path: '/DaiLiShang', name: 'DaiLiShang', component: DaiLiShang },
|
|
{
|
|
path: '/HelpCenter',
|
|
name: 'HelpCenter',
|
|
component: HelpCenter,
|
|
// props: (router) => ({ query: router.query.q })
|
|
},
|
|
|
|
// {
|
|
// path: '/HelpCenter',
|
|
// component: HelpCenter,
|
|
// children: [
|
|
// { path: 'HC211', component: HC211 }
|
|
// ]
|
|
|
|
// },
|
|
{ path: '/TransactionCenter', name: 'TransactionCenter', component: TransactionCenter },
|
|
|
|
{ path: '/AboutUs', name: 'AboutUs', component: AboutUs },
|
|
{ path: '/Report', name: 'Report', component: Report },
|
|
{ path: '/ProductsNews', name: 'ProductsNews', component: ProductsNews },
|
|
|
|
{ path: '/MobilePage', name: 'MobilePage', component: MobilePage },
|
|
],
|
|
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const mobile = isMobile();
|
|
if (mobile && to.name !== 'MobilePage') {
|
|
next({ name: 'MobilePage' });
|
|
} else if (!mobile && to.name === 'MobilePage') {
|
|
next({ name: 'HomePage' });
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
|
|
// 点击路由后滚动条跳转到顶部
|
|
router.afterEach(() => {
|
|
document.body.scrollTop = 0;
|
|
document.documentElement.scrollTop = 0;
|
|
})
|
|
|
|
|
|
// // 创建的路由对象共享出去
|
|
export default router
|
|
|
|
|
|
|