diff options
| author | Haishan <[email protected]> | 2020-09-13 16:34:18 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-09-13 17:16:14 +0800 |
| commit | 15bc0f69a8367a57fa1bf263e615285349ad4ab9 (patch) | |
| tree | fbdd2a46303703822f7e7bc3462a70b4855fe4a1 /src/components/Root.js | |
| parent | a8f0d3d4b4928caebf61c75fa9191a170b471035 (diff) | |
feat: multi backends management
Diffstat (limited to 'src/components/Root.js')
| -rw-r--r-- | src/components/Root.js | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/components/Root.js b/src/components/Root.js index 6c13163..8c06100 100644 --- a/src/components/Root.js +++ b/src/components/Root.js @@ -1,11 +1,12 @@ import './Root.css'; import React, { lazy, Suspense } from 'react'; -import { HashRouter as Router, Route, Routes } from 'react-router-dom'; +import { HashRouter as Router, useRoutes } from 'react-router-dom'; import { RecoilRoot } from 'recoil'; import { About } from 'src/components/about/About'; import { actions, initialState } from '../store'; +import APIConfig from './APIConfig'; import APIDiscovery from './APIDiscovery'; import ErrorBoundary from './ErrorBoundary'; import Home from './Home'; @@ -52,33 +53,50 @@ const Rules = lazy(() => ); const routes = [ - ['home', '/', <Home />], - ['connections', '/connections', <Connections />], - ['configs', '/configs', <Config />], - ['logs', '/logs', <Logs />], - ['proxies', '/proxies', <Proxies />], - ['rules', '/rules', <Rules />], - ['about', '/about', <About />], - __DEV__ ? ['style', '/style', <StyleGuide />] : false, + { path: '/', element: <Home /> }, + { path: '/connections', element: <Connections /> }, + { path: '/configs', element: <Config /> }, + { path: '/logs', element: <Logs /> }, + { path: '/proxies', element: <Proxies /> }, + { path: '/rules', element: <Rules /> }, + { path: '/about', element: <About /> }, + __DEV__ ? { path: '/style', element: <StyleGuide /> } : false, ].filter(Boolean); +function RouteInnerApp() { + return useRoutes(routes); +} + +function SideBarApp() { + return ( + <> + <APIDiscovery /> + <SideBar /> + <div className={s0.content}> + <Suspense fallback={<Loading2 />}> + <RouteInnerApp /> + </Suspense> + </div> + </> + ); +} + +function App() { + return useRoutes([ + { path: '/backend', element: <APIConfig /> }, + { path: '*', element: <SideBarApp /> }, + ]); +} + const Root = () => ( <ErrorBoundary> <RecoilRoot> <StateProvider initialState={initialState} actions={actions}> <Router> <div className={s0.app}> - <APIDiscovery /> - <SideBar /> - <div className={s0.content}> - <Suspense fallback={<Loading2 />}> - <Routes> - {routes.map(([key, path, element]) => ( - <Route key={key} path={path} element={element} /> - ))} - </Routes> - </Suspense> - </div> + <Suspense fallback={<Loading2 />}> + <App /> + </Suspense> </div> </Router> </StateProvider> |
