添加了相关测试文件,引入Tailwindcss
Change-Id: I12054143571bb688590af0357125a0ed26ff2050
diff --git a/src/routes/ProtectedRoute.jsx b/src/routes/ProtectedRoute.jsx
new file mode 100644
index 0000000..ea53b10
--- /dev/null
+++ b/src/routes/ProtectedRoute.jsx
@@ -0,0 +1,35 @@
+import { Navigate } from 'react-router-dom';
+import { useEffect, useState } from 'react';
+import { Spin } from 'antd';
+
+const ProtectedRoute = ({ children }) => {
+ const [loading, setLoading] = useState(true);
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
+
+ useEffect(() => {
+ // 简单检查是否有token
+ const token = localStorage.getItem('token');
+ if (token) {
+ setIsAuthenticated(true);
+ }
+ setLoading(false);
+ }, []);
+
+ if (loading) {
+ return (
+ <div className="flex justify-center items-center h-screen">
+ <Spin spinning={loading} fullScreen tip="加载中...">
+ {children}
+ </Spin>
+ </div>
+ );
+ }
+
+ if (!isAuthenticated) {
+ return <Navigate to="/login" replace />;
+ }
+
+ return children;
+};
+
+export default ProtectedRoute;
\ No newline at end of file