95 lines
2.3 KiB
JavaScript
95 lines
2.3 KiB
JavaScript
import { createRouter, createWebHistory } from "vue-router";
|
|
|
|
const routes = [
|
|
{
|
|
path: "/",
|
|
name: "index1",
|
|
component: () =>
|
|
import(/* webpackChunkName "index1" */ "@/views/TaskView.vue"),
|
|
meta: {
|
|
title: "Gacha",
|
|
canonical: "https://m.gacha.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/quest",
|
|
name: "QUEST",
|
|
meta: {
|
|
title: "Gacha Quest",
|
|
canonical: "https://m.gacha.counterfire.games/quest",
|
|
|
|
},
|
|
component: () =>
|
|
import(/* webpackChunkName "marketplace" */ "@/views/TaskView.vue"),
|
|
},
|
|
{
|
|
path: "/index.html",
|
|
name: "index",
|
|
component: () =>
|
|
import(/* webpackChunkName "index" */ "@/views/TaskView.vue"),
|
|
meta: {
|
|
title: "Gacha index",
|
|
canonical: "https://m.gacha.counterfire.games/index.html",
|
|
|
|
},
|
|
},
|
|
{
|
|
path: "/undertest",
|
|
name: "TaskOne",
|
|
meta: {
|
|
title: "Gacha Undertest",
|
|
canonical: "https://m.gacha.counterfire.games/undertest",
|
|
|
|
},
|
|
component: () =>
|
|
import(/* webpackChunkName "TaskOne" */ "@/components/task/TaskOne.vue"),
|
|
},
|
|
{
|
|
path: "/taskTwo",
|
|
name: "TaskTwo",
|
|
meta: {
|
|
title: "Gacha TaskTwo",
|
|
canonical: "https://m.gacha.counterfire.games/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);
|
|
|
|
// 对于 PC 端官网项目:
|
|
if (isMobile) {
|
|
if (to.meta.title) {
|
|
document.title = to.meta.title;
|
|
}
|
|
let link = document.querySelector("link[rel='canonical']")
|
|
if (!link) {
|
|
link = document.createElement('link')
|
|
link.rel = 'canonical'
|
|
document.head.appendChild(link)
|
|
}
|
|
link.href = to.meta.canonical
|
|
next(); // 如果是 PC 设备,继续导航
|
|
} else {
|
|
window.location.href = `https://gacha.counterfire.games${to.query.code? '?code='+ to.query.code:''}`;
|
|
}
|
|
});
|
|
|
|
export default router;
|