App.js 8.3 KB

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