import React from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';
import MainLayout from '../components/Layout';
import LoginPage from '../pages/Login';
import Dashboard from '../pages/Dashboard';
import DeviceTypePage from '../pages/DeviceType';
import BatchPage from '../pages/Batch';
import BatchDetail from '../pages/Batch/Detail';
import DevicePage from '../pages/Device';
import UserPage from '../pages/User';
import AdminPage from '../pages/Admin';
import { useAuthStore } from '../store/useAuthStore';
// 路由守卫组件
const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { isAuthenticated } = useAuthStore();
if (!isAuthenticated) {
return ;
}
return <>{children}>;
};
// 创建路由
const router = createBrowserRouter([
{
path: '/login',
element: ,
},
{
path: '/',
element: (
),
children: [
{
index: true,
element: ,
},
{
path: 'dashboard',
element: ,
},
{
path: 'device-types',
element: ,
},
{
path: 'batches',
element: ,
},
{
path: 'batches/:id',
element: ,
},
{
path: 'devices',
element: ,
},
{
path: 'users',
element: ,
},
{
path: 'admins',
element: ,
},
],
},
{
path: '*',
element: ,
},
]);
export default router;