index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { createBrowserRouter } from 'react-router-dom';
  2. import Layout from '../layout';
  3. import { Suspense, lazy } from 'react';
  4. const Home = lazy(() => import('../pages/home'));
  5. const Setting = lazy(() => import('../pages/setting'));
  6. const ShopList = lazy(() => import('../pages/shop-list'));
  7. const Login = lazy(() => import('../pages/login'));
  8. const fallbackEle = '加载中...';
  9. const withSuspense = (ComP) => (
  10. <Suspense fallback={fallbackEle}>
  11. <ComP />
  12. </Suspense>
  13. );
  14. export const routes = [
  15. {
  16. path: '/',
  17. element: <Layout />,
  18. children: [
  19. {
  20. index: true,
  21. element: withSuspense(Home),
  22. breadcrumbName: '主页',
  23. },
  24. {
  25. path: '/setting',
  26. element: withSuspense(Setting),
  27. breadcrumbName: '设置',
  28. },
  29. {
  30. path: '/shop-list',
  31. element: withSuspense(ShopList),
  32. breadcrumbName: '商品列表',
  33. },
  34. ],
  35. },
  36. {
  37. path: '/login',
  38. element: withSuspense(Login),
  39. },
  40. ];
  41. const router = createBrowserRouter(routes);
  42. export default router;