index.js
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-07 14:26:52
* @FilePath: /mlaj/src/router/index.js
* @Description: 路由实例创建和导出
*/
import { createRouter, createWebHashHistory } from 'vue-router'
import { routes } from './routes'
import { checkWxAuth, checkAuth } from './guards'
const router = createRouter({
history: createWebHashHistory(import.meta.env.VITE_BASE || '/'),
routes,
scrollBehavior(to, from, savedPosition) {
// 每次路由切换后,页面滚动到顶部
// return savedPosition || { top: 0, left: 0 }
return { top: 0, left: 0 }
},
})
// 导航守卫
router.beforeEach(async (to, from, next) => {
// 微信授权检查
// const wxAuthResult = await checkWxAuth()
// if (wxAuthResult !== true) {
// next(wxAuthResult)
// return
// }
// 检查用户是否已登录
// 登录权限检查
const authResult = checkAuth(to)
if (authResult !== true) {
next(authResult)
return
}
next()
})
export default router