init project

This commit is contained in:
2024-12-24 14:53:00 +08:00
commit f5025aa709
18 changed files with 1341 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
const routes = [
{
path: '/',
name: 'Home',
component: Home,
meta: {
title: '首页'
}
},
// 404 页面
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('../views/NotFound.vue')
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
// 全局前置守卫
router.beforeEach((to, from, next) => {
// 设置页面标题
document.title = to.meta.title || '默认标题'
next()
})
// 全局后置钩子
router.afterEach((to, from) => {
window.scrollTo(0, 0)
})
export default router