2c62a85d
岑健浩
前端代码分支
|
1
2
|
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
|
0ec38cbe
徐振旌
1、新增前端登陆、新增条件查询
|
3
|
import Login from "../views/Login.vue";
|
2c62a85d
岑健浩
前端代码分支
|
4
5
6
7
8
9
10
11
12
|
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: HomeView,
meta: {
|
0ec38cbe
徐振旌
1、新增前端登陆、新增条件查询
|
13
14
15
16
17
18
19
20
21
22
23
|
title: 'SN管理',
requiresAuth: true // 添加这行,标记该路由需要认证
}
},
{
path: '/login',
name: 'Login',
component: Login,
meta: {
requiresAuth: false // 明确表示登录页不需要认证
|
2c62a85d
岑健浩
前端代码分支
|
24
25
26
27
28
|
}
}
]
})
|
0ec38cbe
徐振旌
1、新增前端登陆、新增条件查询
|
29
30
31
32
33
34
35
36
37
38
39
|
// 路由守卫
router.beforeEach((to, from, next) => {
const isAuthenticated = sessionStorage.getItem('isAuthenticated')
if (to.path === '/login' && !isAuthenticated) {
return next('/login')
}
// 需要认证但未登录 → 跳转登录页
if (to.meta.requiresAuth && !isAuthenticated) {
return next('/login')
|
2c62a85d
岑健浩
前端代码分支
|
40
|
}
|
0ec38cbe
徐振旌
1、新增前端登陆、新增条件查询
|
41
42
43
44
45
46
47
48
49
|
// 已登录但访问登录页 → 跳转首页
if (to.path === '/login' && isAuthenticated) {
return next('/')
}
next()
|
2c62a85d
岑健浩
前端代码分支
|
50
51
|
})
|
0ec38cbe
徐振旌
1、新增前端登陆、新增条件查询
|
52
|
|
2c62a85d
岑健浩
前端代码分支
|
53
|
export default router
|