wangfei
2024-10-17 0b8f1db9b9db6ec216091e953303a752c91aa307
UI-Project/src/router/index.js
@@ -3,7 +3,6 @@
// import User from '../views/sys/User.vue'
// import Role from '../views/sys/Role.vue'
// import Menu from '../views/sys/Menu.vue'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
@@ -17,6 +16,11 @@
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/new-page', // 新增的无需登录的页面
      name: 'newPage',
      component: () => import('../views/NewPage.vue')
    },
    {
      path: '/main',
@@ -68,13 +72,18 @@
        /*----------- 上片机 ----------------*/
      {
        path: 'Returns',
        name: 'Returns',
        component: () => import('../views/Returns/returns.vue'),
        name: 'return',
        component: () => import('../views/Returns/return.vue'),
        children:[
          {
            path: '/Returns/returns',
            name: 'returns',
            component: () => import('../views/Returns/returns.vue')
          },
          {
            path: '/Returns/upreturns',
            name: 'upreturns',
            component: () => import('../views/Returns/upreturns.vue')
          },
        ]
      },
@@ -204,7 +213,7 @@
            }
          ]
        },
         /*----------- 可视化系统 ----------------*/
         {
          path: 'Visualization',
@@ -302,7 +311,7 @@
        },
        {
          path: '',
          redirect: '/returns/returns'
          redirect: '/Returns/returns'
        }
      ]
    },
@@ -314,5 +323,14 @@
    
  ]
})
// 导航守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = !!localStorage.getItem('authToken'); // 假设这是你的登录状态检查逻辑
  if (to.matched.some(record => record.meta.requiresAuth) && !isAuthenticated) {
    next({ name: 'login' }); // 如果需要登录但未登录,则重定向到登录页面
  } else {
    next(); // 否则继续导航
  }
});
export default router