index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, {useState} from 'react';
  2. import ReactDOM from 'react-dom';
  3. import * as serviceWorker from './serviceWorker';
  4. import {Route, Router} from 'react-router'
  5. import { createHashHistory } from 'history'
  6. import config from './router.config'
  7. import Header from './layout/Header'
  8. import Slide from './layout/Slide';
  9. import Combination from './layout/Combination'
  10. import { RouteComponentProps, Switch, Redirect } from 'react-router'
  11. const history = createHashHistory()
  12. function App() {
  13. let [route, setRoute] = useState()
  14. let Items = config.map(item => (
  15. <Route
  16. key={item.path}
  17. path={item.path}
  18. component={(r: any) => (
  19. <Combination
  20. {...r}
  21. real={route}
  22. layer={item.component}
  23. className="main"
  24. currentRoute={(r: RouteComponentProps) => (route && r.match.path === route.match.path) || setRoute(r) } />
  25. )}
  26. />
  27. ))
  28. return (
  29. <div className="app">
  30. <Header className='header' />
  31. <div className='section'>
  32. <Router history={history}>
  33. <Route path="/" component={() => <Slide {...route} className='slide' />} />
  34. <Switch>
  35. {Items}
  36. <Redirect to="/gis" />
  37. </Switch>
  38. </Router>
  39. </div>
  40. </div>
  41. )
  42. }
  43. ReactDOM.render(<App />, document.getElementById('root'));
  44. // If you want your app to work offline and load faster, you can change
  45. // unregister() to register() below. Note this comes with some pitfalls.
  46. // Learn more about service workers: https://bit.ly/CRA-PWA
  47. serviceWorker.unregister();