huangjinming 715150e70a fix
2023-07-15 19:58:56 +08:00

78 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createRouter, createWebHistory } from 'vue-router';
import Home from '../views/HomeView.vue';
import GamePromotionEvent from '../views/GamePromotionEvent.vue';
const routes = [
{
path: '/',
name: 'home',
component: Home,
},
// {
// path: '/pre',
// name: 'pre',
// component: () => import(/* webpackChunkName "pre" */ '../views/GameEventBookingView.vue'),
// },
{
path: '/about',
name: 'about',
component: () => import(/* webpackChunkName "about" */ '../views/AboutView.vue'),
},
{
path: '/gallery',
name: 'gallery',
component: () => import(/* webpackChunkName "gallery" */ '@/views/GalleryView.vue'),
},
{
path: '/marketplace',
name: 'marketplace',
component: () => import(/* webpackChunkName "marketplace" */ '@/views/MarketplaceView.vue'),
},
{
path: '/task',
name: 'TASK',
component: () => import(/* webpackChunkName "marketplace" */ '@/views/TaskView.vue'),
},
{
path: '/taskOne',
name: 'TaskOne',
component: () => import(/* webpackChunkName "TaskOne" */ '@/components/task/TaskOne.vue'),
},
{
path: '/taskTwo',
name: 'TaskTwo',
component: () => import(/* webpackChunkName "TaskTwo" */ '@/components/task/TaskTwo.vue'),
},
];
const router = createRouter({
history: createWebHistory(),
routes,
scrollBehavior(to, from, savedPosition) {
return { top: 0 };
},
});
function isMobileDevice(userAgent) {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);
}
router.beforeEach((to, from, next) => {
const isMobile = isMobileDevice(window.navigator.userAgent);
// 检查URL中是否包含code参数
if (to.query.code) {
// 如果包含,那么重定向到另一个网站,并且携带邀请码
window.location.href = `https://gacha.counterfire.games/?code=${to.query.code}`
} else if (isMobile) {
// 如果是移动设备,重定向到移动版的网站
window.location.href = 'https://m.counterfire.games/';
} else {
// 如果不包含code参数并且不是移动设备那么正常导航
next()
}
})
export default router;