import { Navigate, createBrowserRouter } from 'react-router-dom';
import Login from './pages/Login';
import Dashboard from './pages/Dashboard';
import Silkworm from './pages/Silkworm';
import Device from './pages/Device';
import Energy from './pages/Energy';
import Control from './pages/Control';
import IRControl from './pages/IRControl';
import Threshold from './pages/Threshold';
import Alert from './pages/Alert';
import Video from './pages/Video';
import Log from './pages/Log';
import Knowledge from './pages/Knowledge';
import Batches from './pages/Batches';
import NotFound from './pages/NotFound';
import { BasicLayout } from './layout/BasicLayout';
import { authService } from './services/auth';
const RequireAuth = ({ children }: { children: React.ReactNode }) => {
if (!authService.isLoggedIn()) return ;
return <>{children}>;
};
// 路由权限守卫:未登录跳登录页,无权限跳仪表盘
const RequirePermission = ({ permission, children }: { permission: string; children: React.ReactNode }) => {
if (!authService.isLoggedIn()) return ;
if (!authService.hasPermission(permission)) return ;
return <>{children}>;
};
export const router = createBrowserRouter([
{ path: '/login', element: },
{
element: (
),
children: [
{ index: true, element: },
{ path: 'dashboard', element: },
{ path: 'houses', element: },
{ path: 'devices', element: },
{ path: 'energy', element: },
{ path: 'control', element: },
{ path: 'ir', element: },
{ path: 'thresholds', element: },
{ path: 'alerts', element: },
{ path: 'videos', element: },
{ path: 'logs', element: },
{ path: 'knowledge', element: },
{ path: 'batches', element: },
{ path: '404', element: },
],
},
{ path: '*', element: },
]);