index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, {Suspense} from 'react';
  2. import ReactDOM from 'react-dom';
  3. import './index.css';
  4. import reportWebVitals from './reportWebVitals';
  5. import {createBrowserRouter, RouterProvider, Route, Link} from "react-router-dom";
  6. import {SnackbarProvider} from 'notistack';
  7. const Home2 = React.lazy(() => import('./Home2'));
  8. const App2 = React.lazy(() => import('./App2'));
  9. const AI = React.lazy(() => import('./AI'));
  10. const Signin = React.lazy(() => import('./Signin'));
  11. const notFoundStyle = {
  12. display: 'flex',
  13. justifyContent: 'center',
  14. alignItems: 'center',
  15. height: '100vh',
  16. flexDirection: 'column',
  17. backgroundColor: '#f4f4f9',
  18. color: '#333',
  19. fontFamily: 'Arial, sans-serif',
  20. textAlign: 'center',
  21. };
  22. const headingStyle = {
  23. fontSize: '4rem',
  24. fontWeight: 'bold',
  25. margin: '0',
  26. };
  27. const subheadingStyle = {
  28. fontSize: '1.5rem',
  29. marginTop: '20px',
  30. };
  31. const emojiStyle = {
  32. fontSize: '5rem',
  33. marginBottom: '20px',
  34. };
  35. function ErrorBoundary() {
  36. return (
  37. <div style={notFoundStyle}>
  38. <div style={emojiStyle}>🚫</div>
  39. <h1 style={headingStyle}>小造同学遇到了一点麻烦</h1>
  40. <p style={subheadingStyle}>请刷新页面重试,我们会积极尝试优化体验</p>
  41. </div>)
  42. }
  43. const router = createBrowserRouter([
  44. {path: "/editor/qingdan/:id",
  45. element: (<Suspense fallback={<div></div>}><SnackbarProvider><App2></App2></SnackbarProvider></Suspense>),
  46. errorElement : (<ErrorBoundary />)
  47. },
  48. {path: "/editor/index.html",
  49. element: (<Suspense fallback={<div></div>}><Home2></Home2></Suspense>)
  50. },
  51. {path: "/editor/ai",
  52. element: (<Suspense fallback={<div></div>}><AI></AI></Suspense>)
  53. },
  54. {path: "/editor/signin",
  55. element: (<Suspense fallback={<div></div>}><Signin></Signin></Suspense>)
  56. },
  57. ]);
  58. const root = ReactDOM.render(<RouterProvider router={router}/>, document.getElementById('root'));
  59. // If you want to start measuring performance in your app, pass a function
  60. // to log results (for example: reportWebVitals(console.log))
  61. // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
  62. reportWebVitals();