fix: connect API to tracker.db via SQLite repository
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 更新路由,添加 Admin 和 Billing 页面
|
||||
*/
|
||||
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
||||
import MainLayout from '@/components/layout/MainLayout';
|
||||
import Login from '@/pages/auth/Login';
|
||||
import Register from '@/pages/auth/Register';
|
||||
import ForgotPassword from '@/pages/auth/ForgotPassword';
|
||||
import ResetPassword from '@/pages/auth/ResetPassword';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
// 受保护的路由组件
|
||||
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
|
||||
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
// 路由配置
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: '/login',
|
||||
element: <Login />,
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
element: <Register />,
|
||||
},
|
||||
{
|
||||
path: '/forgot-password',
|
||||
element: <ForgotPassword />,
|
||||
},
|
||||
{
|
||||
path: '/reset-password',
|
||||
element: <ResetPassword />,
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
element: (
|
||||
<ProtectedRoute>
|
||||
<MainLayout />
|
||||
</ProtectedRoute>
|
||||
),
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
element: <Navigate to="/workspaces" replace />,
|
||||
},
|
||||
{
|
||||
path: 'workspaces',
|
||||
lazy: () => import('@/pages/workspace/WorkspaceList'),
|
||||
},
|
||||
{
|
||||
path: 'workspaces/:id',
|
||||
lazy: () => import('@/pages/workspace/WorkspaceDetail'),
|
||||
},
|
||||
{
|
||||
path: 'subscription',
|
||||
lazy: () => import('@/pages/subscription/Plans'),
|
||||
},
|
||||
{
|
||||
path: 'subscription/upgrade/:workspaceId',
|
||||
lazy: () => import('@/pages/subscription/UpgradeSubscription'),
|
||||
},
|
||||
{
|
||||
path: 'subscription/billing',
|
||||
lazy: () => import('@/pages/subscription/Billing'),
|
||||
},
|
||||
{
|
||||
path: 'admin',
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
lazy: () => import('@/pages/admin/Dashboard'),
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
lazy: () => import('@/pages/admin/UserManagement'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
lazy: () => import('@/pages/profile/Settings'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: <Navigate to="/" replace />,
|
||||
},
|
||||
]);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user