146 lines
3.4 KiB
JavaScript
146 lines
3.4 KiB
JavaScript
import { createRouter, createWebHistory } from "vue-router";
|
|
import HomeView from "../views/HomeView.vue";
|
|
import AboutView from "../views/AboutView.vue";
|
|
import MarketplaceView from "../views/MarketplaceView.vue";
|
|
import Assets from "../views/AssetsView.vue";
|
|
import Notice from "../views/NoticeView.vue"
|
|
import Detail from "../views/DetailView.vue";
|
|
import PrivacyView from '../views/PrivacyView.vue';
|
|
import TermsView from '../views/TermsView.vue';
|
|
const routes = [
|
|
{
|
|
path: "/",
|
|
name: "index1",
|
|
component: HomeView,
|
|
meta: {
|
|
title: "Counter Fire",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/about",
|
|
name: "About",
|
|
component: AboutView,
|
|
meta: {
|
|
title: "Counter Fire-About",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/marketplace",
|
|
name: "Marketplace",
|
|
component: MarketplaceView,
|
|
meta: {
|
|
title: "Counter Fire-Marketplace",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/detail",
|
|
name: "CDetail",
|
|
component: Detail,
|
|
props: true,
|
|
meta: {
|
|
title: "Counter Fire-Detail",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/detail/:address/:tokenid",
|
|
name: "Detail",
|
|
component: Detail,
|
|
props: true,
|
|
meta: {
|
|
title: "Counter Fire-Detail",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/assets",
|
|
name: "Assets",
|
|
component: Assets,
|
|
meta: {
|
|
title: "Counter Fire-Assets",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/notice",
|
|
name: "Notice",
|
|
component: Notice,
|
|
meta: {
|
|
title: "Counter Fire-Assets",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/privacy",
|
|
name: "Privacy",
|
|
component: PrivacyView,
|
|
meta: {
|
|
title: "Counter Fire-Privacy",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
{
|
|
path: "/terms",
|
|
name: "Terms",
|
|
component: TermsView,
|
|
meta: {
|
|
title: "Counter Fire-Terms",
|
|
canonical: "https://.counterfire.games",
|
|
},
|
|
},
|
|
|
|
|
|
];
|
|
|
|
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;
|
|
|
|
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.gacha.counterfire.games${ to.query.code ? '?code=' + to.query.code : ""
|
|
// }`;
|
|
next();
|
|
}
|
|
});
|
|
|
|
export default router;
|