chore: init
This commit is contained in:
39
src/router/index.js
Normal file
39
src/router/index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import BattleRanking from '../views/BattleRanking.vue';
|
||||
import AdminPanel from '../views/AdminPanel.vue';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'BattleRanking',
|
||||
component: BattleRanking,
|
||||
meta: { title: '百人大战排行榜' }
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'AdminPanel',
|
||||
component: AdminPanel,
|
||||
meta: { title: '管理员面板' }
|
||||
},
|
||||
{
|
||||
// 捕获所有未匹配的路由,重定向到首页
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: '/'
|
||||
}
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
// 全局前置守卫,设置页面标题
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 设置文档标题
|
||||
if (to.meta.title) {
|
||||
document.title = to.meta.title;
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user