index.js 951 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 fallbackEle = '加载中...';
  8. const withSuspense = (ComP) => (
  9. <Suspense fallback={fallbackEle}>
  10. <ComP />
  11. </Suspense>
  12. );
  13. export const routes = [
  14. {
  15. path: '/',
  16. element: <Layout />,
  17. children: [
  18. {
  19. index: true,
  20. element: withSuspense(Home),
  21. breadcrumbName: '主页',
  22. },
  23. {
  24. path: '/setting',
  25. element: withSuspense(Setting),
  26. breadcrumbName: '设置',
  27. },
  28. {
  29. path: '/shop-list',
  30. element: withSuspense(ShopList),
  31. breadcrumbName: '商品列表',
  32. },
  33. ],
  34. },
  35. ];
  36. const router = createBrowserRouter(routes);
  37. export default router;