From 4ef42ab4a5e19ca88ea4000cac71e572cb59d48d Mon Sep 17 00:00:00 2001 From: Coldin04 Date: Fri, 25 Apr 2025 22:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E8=B7=AF=E7=94=B1=E6=B7=BB=E5=8A=A0me?= =?UTF-8?q?ta=E4=BF=A1=E6=81=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/router/index.ts b/src/router/index.ts index 0e4752b..9b86e59 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,8 @@ import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/HomeView.vue' + + const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ @@ -8,6 +10,9 @@ const router = createRouter({ path: '/', name: 'home', component: HomeView, + meta: { + title: '首页' + } }, { path: '/about', @@ -16,18 +21,34 @@ const router = createRouter({ // this generates a separate chunk (About.[hash].js) for this route // which is lazy-loaded when the route is visited. component: () => import('../views/AboutView.vue'), + meta: { + title: '关于' + } }, { path: '/practice', name: 'Practice', component: () => import('../views/Practice.vue'), + meta: { + title: '单人练习' + } }, { path: '/network-battle', name: 'NetworkBattle', component: () => import('../views/NetworkBattle.vue'), + meta: { + title: '在线比赛' + } }, ], }) +// 全局前置守卫:在每次导航前执行 +router.beforeEach((to, from, next) => { + // 从路由的meta中获取title,并设置给页面标题 + document.title = to.meta.title ? `${to.meta.title} - ArithmaBattle` : 'ArithmaBattle' + next() +}) + export default router