App.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import React, { lazy, Suspense, useContext, useEffect } from 'react';
  2. import { Route, Routes, useLocation } from 'react-router-dom';
  3. import Loading from './components/Loading';
  4. import User from './pages/User';
  5. import { PrivateRoute } from './components/PrivateRoute';
  6. import RegisterForm from './components/RegisterForm';
  7. import LoginForm from './components/LoginForm';
  8. import NotFound from './pages/NotFound';
  9. import Setting from './pages/Setting';
  10. import EditUser from './pages/User/EditUser';
  11. import PasswordResetForm from './components/PasswordResetForm';
  12. import PasswordResetConfirm from './components/PasswordResetConfirm';
  13. import Channel from './pages/Channel';
  14. import Token from './pages/Token';
  15. import EditChannel from './pages/Channel/EditChannel';
  16. import Redemption from './pages/Redemption';
  17. import TopUp from './pages/TopUp';
  18. import Log from './pages/Log';
  19. import Chat from './pages/Chat';
  20. import Chat2Link from './pages/Chat2Link';
  21. import { Layout } from '@douyinfe/semi-ui';
  22. import Midjourney from './pages/Midjourney';
  23. import Pricing from './pages/Pricing/index.js';
  24. import Task from './pages/Task/index.js';
  25. import Playground from './pages/Playground/Playground.js';
  26. import OAuth2Callback from './components/OAuth2Callback.js';
  27. import PersonalSetting from './components/PersonalSetting.js';
  28. import Setup from './pages/Setup/index.js';
  29. const Home = lazy(() => import('./pages/Home'));
  30. const Detail = lazy(() => import('./pages/Detail'));
  31. const About = lazy(() => import('./pages/About'));
  32. function App() {
  33. const location = useLocation();
  34. return (
  35. <>
  36. <Routes>
  37. <Route
  38. path='/'
  39. element={
  40. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  41. <Home />
  42. </Suspense>
  43. }
  44. />
  45. <Route
  46. path='/setup'
  47. element={
  48. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  49. <Setup />
  50. </Suspense>
  51. }
  52. />
  53. <Route
  54. path='/channel'
  55. element={
  56. <PrivateRoute>
  57. <Channel />
  58. </PrivateRoute>
  59. }
  60. />
  61. <Route
  62. path='/channel/edit/:id'
  63. element={
  64. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  65. <EditChannel />
  66. </Suspense>
  67. }
  68. />
  69. <Route
  70. path='/channel/add'
  71. element={
  72. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  73. <EditChannel />
  74. </Suspense>
  75. }
  76. />
  77. <Route
  78. path='/token'
  79. element={
  80. <PrivateRoute>
  81. <Token />
  82. </PrivateRoute>
  83. }
  84. />
  85. <Route
  86. path='/playground'
  87. element={
  88. <PrivateRoute>
  89. <Playground />
  90. </PrivateRoute>
  91. }
  92. />
  93. <Route
  94. path='/redemption'
  95. element={
  96. <PrivateRoute>
  97. <Redemption />
  98. </PrivateRoute>
  99. }
  100. />
  101. <Route
  102. path='/user'
  103. element={
  104. <PrivateRoute>
  105. <User />
  106. </PrivateRoute>
  107. }
  108. />
  109. <Route
  110. path='/user/edit/:id'
  111. element={
  112. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  113. <EditUser />
  114. </Suspense>
  115. }
  116. />
  117. <Route
  118. path='/user/edit'
  119. element={
  120. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  121. <EditUser />
  122. </Suspense>
  123. }
  124. />
  125. <Route
  126. path='/user/reset'
  127. element={
  128. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  129. <PasswordResetConfirm />
  130. </Suspense>
  131. }
  132. />
  133. <Route
  134. path='/login'
  135. element={
  136. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  137. <LoginForm />
  138. </Suspense>
  139. }
  140. />
  141. <Route
  142. path='/register'
  143. element={
  144. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  145. <RegisterForm />
  146. </Suspense>
  147. }
  148. />
  149. <Route
  150. path='/reset'
  151. element={
  152. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  153. <PasswordResetForm />
  154. </Suspense>
  155. }
  156. />
  157. <Route
  158. path='/oauth/github'
  159. element={
  160. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  161. <OAuth2Callback type='github'></OAuth2Callback>
  162. </Suspense>
  163. }
  164. />
  165. <Route
  166. path='/oauth/oidc'
  167. element={
  168. <Suspense fallback={<Loading></Loading>}>
  169. <OAuth2Callback type='oidc'></OAuth2Callback>
  170. </Suspense>
  171. }
  172. />
  173. <Route
  174. path='/oauth/linuxdo'
  175. element={
  176. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  177. <OAuth2Callback type='linuxdo'></OAuth2Callback>
  178. </Suspense>
  179. }
  180. />
  181. <Route
  182. path='/setting'
  183. element={
  184. <PrivateRoute>
  185. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  186. <Setting />
  187. </Suspense>
  188. </PrivateRoute>
  189. }
  190. />
  191. <Route
  192. path='/personal'
  193. element={
  194. <PrivateRoute>
  195. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  196. <PersonalSetting />
  197. </Suspense>
  198. </PrivateRoute>
  199. }
  200. />
  201. <Route
  202. path='/topup'
  203. element={
  204. <PrivateRoute>
  205. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  206. <TopUp />
  207. </Suspense>
  208. </PrivateRoute>
  209. }
  210. />
  211. <Route
  212. path='/log'
  213. element={
  214. <PrivateRoute>
  215. <Log />
  216. </PrivateRoute>
  217. }
  218. />
  219. <Route
  220. path='/detail'
  221. element={
  222. <PrivateRoute>
  223. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  224. <Detail />
  225. </Suspense>
  226. </PrivateRoute>
  227. }
  228. />
  229. <Route
  230. path='/midjourney'
  231. element={
  232. <PrivateRoute>
  233. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  234. <Midjourney />
  235. </Suspense>
  236. </PrivateRoute>
  237. }
  238. />
  239. <Route
  240. path='/task'
  241. element={
  242. <PrivateRoute>
  243. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  244. <Task />
  245. </Suspense>
  246. </PrivateRoute>
  247. }
  248. />
  249. <Route
  250. path='/pricing'
  251. element={
  252. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  253. <Pricing />
  254. </Suspense>
  255. }
  256. />
  257. <Route
  258. path='/about'
  259. element={
  260. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  261. <About />
  262. </Suspense>
  263. }
  264. />
  265. <Route
  266. path='/chat/:id?'
  267. element={
  268. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  269. <Chat />
  270. </Suspense>
  271. }
  272. />
  273. {/* 方便使用chat2link直接跳转聊天... */}
  274. <Route
  275. path='/chat2link'
  276. element={
  277. <PrivateRoute>
  278. <Suspense fallback={<Loading></Loading>} key={location.pathname}>
  279. <Chat2Link />
  280. </Suspense>
  281. </PrivateRoute>
  282. }
  283. />
  284. <Route path='*' element={<NotFound />} />
  285. </Routes>
  286. </>
  287. );
  288. }
  289. export default App;