App.js 8.3 KB

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