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 = [
{
path: '/',
redirect: '/quest',
path: "/",
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',
name: 'QUEST',
component: () => import(/* webpackChunkName "marketplace" */ '@/views/TaskView.vue'),
path: "/quest",
name: "QUEST",
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',
name: 'index',
component: () => import(/* webpackChunkName "index" */ '@/views/TaskView.vue'),
path: "/index.html",
name: "index",
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',
name: 'TaskOne',
component: () => import(/* webpackChunkName "TaskOne" */ '@/components/task/TaskOne.vue'),
path: "/undertest",
name: "TaskOne",
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',
name: 'TaskTwo',
component: () => import(/* webpackChunkName "TaskTwo" */ '@/components/task/TaskTwo.vue'),
path: "/taskTwo",
name: "TaskTwo",
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) {
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) => {
@ -46,9 +77,31 @@ router.beforeEach((to, from, next) => {
// 对于 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
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 设备,继续导航
} 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 : ""
}`;
}
});