Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 1 | import React from 'react'; |
| 2 | import { Route, useLocation } from 'wouter'; |
| 3 | import { UserProvider, useUser } from './context/UserContext'; |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 4 | |
Krishya | 1df0589 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 5 | import AuthPage from './pages/AuthPage/AuthPage'; |
Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 6 | import HomePage from './pages/HomePage'; |
Krishya | e71688a | 2025-04-10 21:25:17 +0800 | [diff] [blame] | 7 | import FriendMoments from './pages/FriendMoments/FriendMoments'; |
Krishya | 7ec1dd0 | 2025-04-19 15:29:03 +0800 | [diff] [blame] | 8 | import ForumPage from './pages/Forum/posts-main/ForumPage'; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 9 | import SeedList from './pages/SeedList/SeedList'; |
Krishya | 7ec1dd0 | 2025-04-19 15:29:03 +0800 | [diff] [blame] | 10 | import PostDetailPage from './pages/Forum/posts-detail/PostDetailPage'; |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 11 | import { GroupProvider } from './context/useGroupStore'; |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 12 | import PublishSeed from './pages/PublishSeed/PublishSeed'; |
Krishya | 8f2fec8 | 2025-06-04 21:54:46 +0800 | [diff] [blame] | 13 | import SeedDetail from './pages/SeedList/SeedDetail/SeedDetail'; |
22301009 | 3a876cc | 2025-04-14 16:22:20 +0800 | [diff] [blame] | 14 | import InterestGroup from './pages/InterestGroup/InterestGroup'; |
22301009 | 7ff51f2 | 2025-04-15 21:35:28 +0800 | [diff] [blame] | 15 | import UserProfile from './pages/UserCenter/UserProfile'; |
Krishya | 7ec1dd0 | 2025-04-19 15:29:03 +0800 | [diff] [blame] | 16 | import CreatePostPage from './pages/Forum/posts-create/CreatePostPage'; |
Krishya | f1d0ea8 | 2025-05-03 17:01:58 +0800 | [diff] [blame] | 17 | import MessagePage from './pages/MessagePage/MessagePage'; |
| 18 | import CreateMoment from './pages/FriendMoments/CreateMoment'; |
Krishya | 2283d88 | 2025-05-27 22:25:19 +0800 | [diff] [blame] | 19 | import LevelPage from './pages/LevelPage/LevelPage'; |
Krishya | 2e0f49a | 2025-05-29 10:59:01 +0800 | [diff] [blame] | 20 | import NewbieTasks from './pages/UserCenter/NewbieTasks'; |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 21 | import UserDynamics from './pages/UserCenter/UserDynamics'; |
22301009 | 648cb7e | 2025-06-04 08:54:23 +0800 | [diff] [blame] | 22 | import UserFriends from './pages/UserCenter/UserFriends'; |
22301009 | 6401163 | 2025-06-04 21:57:22 +0800 | [diff] [blame] | 23 | import UserCollect from './pages/UserCenter/UserCollect'; |
Krishya | 7096ab1 | 2025-06-05 17:15:46 +0800 | [diff] [blame] | 24 | import UserInvite from './pages/UserCenter/UserInvite'; |
Krishya | 767f9b9 | 2025-06-05 23:59:37 +0800 | [diff] [blame] | 25 | import UserInfo from './pages/UserInfo/UserInfo'; |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 26 | import UserLayout from './pages/UserCenter/UserLayout'; |
| 27 | |
Krishya | 8f2fec8 | 2025-06-04 21:54:46 +0800 | [diff] [blame] | 28 | function RedirectToAuth() { |
| 29 | if (typeof window !== 'undefined') { |
| 30 | window.location.replace('/auth'); |
| 31 | } |
| 32 | return null; |
| 33 | } |
| 34 | |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 35 | // 私有路由保护组件 |
| 36 | function PrivateRoute({ component: Component }) { |
| 37 | const [location, setLocation] = useLocation(); |
| 38 | const { user, loading } = useUser(); |
| 39 | |
| 40 | if (loading) { |
| 41 | return <div>加载中...</div>; |
| 42 | } |
| 43 | |
| 44 | if (!user) { |
| 45 | setLocation('/auth'); |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | return <Component />; |
| 50 | } |
| 51 | |
Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 52 | function App() { |
| 53 | return ( |
| 54 | <UserProvider> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 55 | <GroupProvider> |
Krishya | b5ef96d | 2025-06-05 13:57:05 +0800 | [diff] [blame] | 56 | <> |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 57 | {/* 公开路由 */} |
Krishya | b5ef96d | 2025-06-05 13:57:05 +0800 | [diff] [blame] | 58 | <Route path="/auth" component={AuthPage} /> |
Krishya | 767f9b9 | 2025-06-05 23:59:37 +0800 | [diff] [blame] | 59 | |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 60 | {/* 根路径跳转到登录页 */} |
| 61 | <Route path="/" component={() => <RedirectToAuth />} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 62 | |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 63 | {/* 私有路由用 PrivateRoute 包裹 */} |
| 64 | <Route path="/friend-moments" component={() => <PrivateRoute component={FriendMoments} />} /> |
| 65 | <Route path="/friend-moments/create" component={() => <PrivateRoute component={CreateMoment} />} /> |
| 66 | <Route path="/forum" component={() => <PrivateRoute component={ForumPage} />} /> |
| 67 | <Route path="/forum/post/:postId" component={({ postId }) => <PrivateRoute component={() => <PostDetailPage postId={postId} />} />} /> |
| 68 | <Route path="/forum/create-post" component={() => <PrivateRoute component={CreatePostPage} />} /> |
| 69 | <Route path="/seed-list" component={() => <PrivateRoute component={SeedList} />} /> |
| 70 | <Route path="/publish-seed" component={() => <PrivateRoute component={PublishSeed} />} /> |
| 71 | <Route path="/seed/:id" component={({ id }) => <PrivateRoute component={() => <SeedDetail id={id} />} />} /> |
| 72 | <Route path="/interest-groups" component={() => <PrivateRoute component={InterestGroup} />} /> |
| 73 | <Route path="/messages" component={() => <PrivateRoute component={MessagePage} />} /> |
| 74 | <Route path="/level" component={() => <PrivateRoute component={LevelPage} />} /> |
| 75 | <Route path="/information/:userId" component={({ userId }) => <PrivateRoute component={() => <UserInfo userId={userId} />} />} /> |
| 76 | |
| 77 | {/* 用户中心路由 */} |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 78 | <Route path="/user/profile" component={() => ( |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 79 | <PrivateRoute component={() => <UserLayout><UserProfile /></UserLayout>} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 80 | )} /> |
| 81 | <Route path="/user/newbie-tasks" component={() => ( |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 82 | <PrivateRoute component={() => <UserLayout><NewbieTasks /></UserLayout>} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 83 | )} /> |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 84 | <Route path="/user/dynamics" component={() => ( |
| 85 | <PrivateRoute component={() => <UserLayout><UserDynamics /></UserLayout>} /> |
| 86 | )} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 87 | <Route path="/user/friends" component={() => ( |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 88 | <PrivateRoute component={() => <UserLayout><UserFriends /></UserLayout>} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 89 | )} /> |
| 90 | <Route path="/user/collections" component={() => ( |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 91 | <PrivateRoute component={() => <UserLayout><UserCollect /></UserLayout>} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 92 | )} /> |
| 93 | <Route path="/user/invite" component={() => ( |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 94 | <PrivateRoute component={() => <UserLayout><UserInvite /></UserLayout>} /> |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 95 | )} /> |
Krishya | b5ef96d | 2025-06-05 13:57:05 +0800 | [diff] [blame] | 96 | </> |
| 97 | </GroupProvider> |
Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 98 | </UserProvider> |
| 99 | ); |
| 100 | } |
| 101 | |
Krishya | c6b2483 | 2025-06-05 20:13:20 +0800 | [diff] [blame] | 102 | export default App; |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame^] | 103 | |
| 104 | |
| 105 | // // export default App; |
| 106 | |
| 107 | // import { Route } from 'wouter'; |
| 108 | // import { Redirect } from 'wouter'; |
| 109 | // import AuthPage from './pages/AuthPage/AuthPage'; |
| 110 | // import HomePage from './pages/HomePage'; |
| 111 | // import FriendMoments from './pages/FriendMoments/FriendMoments'; |
| 112 | // import ForumPage from './pages/Forum/posts-main/ForumPage'; |
| 113 | // import SeedList from './pages/SeedList/SeedList'; |
| 114 | // import PostDetailPage from './pages/Forum/posts-detail/PostDetailPage'; |
| 115 | // import { UserProvider } from './context/UserContext'; |
| 116 | // import { GroupProvider } from './context/useGroupStore'; |
| 117 | // import PublishSeed from './pages/PublishSeed/PublishSeed'; |
| 118 | // import SeedDetail from './pages/SeedList/SeedDetail/SeedDetail'; |
| 119 | // import InterestGroup from './pages/InterestGroup/InterestGroup'; |
| 120 | // import UserProfile from './pages/UserCenter/UserProfile'; |
| 121 | // import CreatePostPage from './pages/Forum/posts-create/CreatePostPage'; |
| 122 | // import MessagePage from './pages/MessagePage/MessagePage'; |
| 123 | // import CreateMoment from './pages/FriendMoments/CreateMoment'; |
| 124 | // // import PromotionsPage from './pages/PromotionsPage/PromotionsPage'; |
| 125 | // import LevelPage from './pages/LevelPage/LevelPage'; |
| 126 | // import NewbieTasks from './pages/UserCenter/NewbieTasks'; |
| 127 | // import UserDynamics from './pages/UserCenter/UserDynamics'; |
| 128 | // import UserFriends from './pages/UserCenter/UserFriends'; |
| 129 | // import UserCollect from './pages/UserCenter/UserCollect'; |
| 130 | // import UserInvite from './pages/UserCenter/UserInvite'; |
| 131 | // import UserInfo from './pages/UserInfo/UserInfo'; |
| 132 | // import UserLayout from './pages/UserCenter/UserLayout'; |
| 133 | |
| 134 | // function RedirectToAuth() { |
| 135 | // if (typeof window !== 'undefined') { |
| 136 | // window.location.replace('/auth'); |
| 137 | // } |
| 138 | // return null; |
| 139 | // } |
| 140 | |
| 141 | // function App() { |
| 142 | // return ( |
| 143 | // <UserProvider> |
| 144 | // <GroupProvider> |
| 145 | // <> |
| 146 | // <Route path="/" component={RedirectToAuth} /> |
| 147 | // <Route path="/auth" component={AuthPage} /> |
| 148 | // <Route path="/friend-moments" component={FriendMoments} /> |
| 149 | // <Route path="/friend-moments/create" component={CreateMoment} /> |
| 150 | // <Route path="/forum" component={ForumPage} /> |
| 151 | // <Route path="/forum/post/:postId" component={PostDetailPage} /> |
| 152 | // <Route path="/forum/create-post" component={CreatePostPage} /> |
| 153 | // <Route path="/seed-list" component={SeedList} /> |
| 154 | // <Route path="/publish-seed" component={PublishSeed} /> |
| 155 | // {/* <Route path="/publish-seed" component={SimpleUploader} /> */} |
| 156 | // <Route path="/seed/:id" component={SeedDetail} /> |
| 157 | // <Route path="/interest-groups" component={InterestGroup} /> |
| 158 | // <Route path="/messages" component={MessagePage} /> |
| 159 | // {/* <Route path="/promotions" component={PromotionsPage} /> */} |
| 160 | // <Route path="/level" component={LevelPage} /> |
| 161 | // <Route path="/information/:userId" component={UserInfo} /> |
| 162 | |
| 163 | |
| 164 | // {/* 用户中心嵌套路由模拟 */} |
| 165 | // <Route path="/user/profile" component={() => ( |
| 166 | // <UserLayout><UserProfile /></UserLayout> |
| 167 | // )} /> |
| 168 | // <Route path="/user/newbie-tasks" component={() => ( |
| 169 | // <UserLayout><NewbieTasks /></UserLayout> |
| 170 | // )} /> |
| 171 | // <Route path="/user/dynamics" component={() => ( |
| 172 | // <UserLayout><UserDynamics /></UserLayout> |
| 173 | // )} /> |
| 174 | // <Route path="/user/friends" component={() => ( |
| 175 | // <UserLayout><UserFriends /></UserLayout> |
| 176 | // )} /> |
| 177 | // <Route path="/user/collections" component={() => ( |
| 178 | // <UserLayout><UserCollect /></UserLayout> |
| 179 | // )} /> |
| 180 | // <Route path="/user/invite" component={() => ( |
| 181 | // <UserLayout><UserInvite /></UserLayout> |
| 182 | // )} /> |
| 183 | // </> |
| 184 | // </GroupProvider> |
| 185 | // </UserProvider> |
| 186 | // ); |
| 187 | // } |
| 188 | |
| 189 | // export default App; |