This commit is contained in:
huangjinming 2023-07-03 13:56:29 +08:00
parent 05c04fe7ce
commit 487b0bb8df
2 changed files with 72 additions and 19 deletions

Binary file not shown.

View File

@ -1,31 +1,60 @@
import { createRouter, createWebHistory } from 'vue-router'; import { createRouter, createWebHistory } from "vue-router";
const routes = [ const routes = [
{ {
path: '/', path: "/",
redirect: '/quest', name: "index1",
component: () =>
import(/* webpackChunkName "index1" */ "@/views/TaskView.vue"),
meta: {
title: "Counter Fire",
canonical: "https://www.counterfire.games",
alternate: "https://m.counterfire.games",
},
}, },
{ {
path: '/quest', path: "/quest",
name: 'QUEST', name: "QUEST",
component: () => import(/* webpackChunkName "marketplace" */ '@/views/TaskView.vue'), meta: {
title: "Counter Fire Quest",
canonical: "https://www.counterfire.games/quest",
alternate: "https://m.counterfire.games/quest",
},
component: () =>
import(/* webpackChunkName "marketplace" */ "@/views/TaskView.vue"),
}, },
{ {
path: '/index.html', path: "/index.html",
name: 'index', name: "index",
component: () => import(/* webpackChunkName "index" */ '@/views/TaskView.vue'), component: () =>
import(/* webpackChunkName "index" */ "@/views/TaskView.vue"),
meta: {
title: "Counter Fire index",
canonical: "https://www.counterfire.games/index.html",
alternate: "https://m.counterfire.games/index.html",
},
}, },
{ {
path: '/undertest', path: "/undertest",
name: 'TaskOne', name: "TaskOne",
component: () => import(/* webpackChunkName "TaskOne" */ '@/components/task/TaskOne.vue'), meta: {
title: "Counter Fire Undertest",
canonical: "https://www.counterfire.games/undertest",
alternate: "https://m.counterfire.games/undertest",
},
component: () =>
import(/* webpackChunkName "TaskOne" */ "@/components/task/TaskOne.vue"),
}, },
{ {
path: '/taskTwo', path: "/taskTwo",
name: 'TaskTwo', name: "TaskTwo",
component: () => import(/* webpackChunkName "TaskTwo" */ '@/components/task/TaskTwo.vue'), meta: {
title: "Counter Fire TaskTwo",
canonical: "https://www.counterfire.games/taskTwo",
alternate: "https://m.counterfire.games/taskTwo",
},
component: () =>
import(/* webpackChunkName "TaskTwo" */ "@/components/task/TaskTwo.vue"),
}, },
]; ];
@ -38,7 +67,9 @@ const router = createRouter({
}); });
function isMobileDevice(userAgent) { function isMobileDevice(userAgent) {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent); return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
userAgent
);
} }
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
@ -46,9 +77,31 @@ router.beforeEach((to, from, next) => {
// 对于 PC 端官网项目: // 对于 PC 端官网项目:
if (!isMobile) { 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
let alternateLink = document.querySelector("link[rel='alternate']")
if (!alternateLink) {
alternateLink = document.createElement('link')
alternateLink.rel = 'alternate'
alternateLink.media = 'only screen and (max-width: 640px)'
document.head.appendChild(alternateLink)
}
alternateLink.href = to.meta.alternate
next(); // 如果是 PC 设备,继续导航 next(); // 如果是 PC 设备,继续导航
} else { } else {
window.location.href = `https://m.counterfire.games?code=${to.query.code? to.query.code:''}`; window.location.href = `https://m.counterfire.games?code=${
to.query.code ? to.query.code : ""
}`;
} }
}); });