Blame view

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