|
1 | | -import React from 'react'; |
| 1 | +import React, { lazy, Suspense } from 'react'; |
2 | 2 | import { BrowserRouter } from 'react-router-dom'; |
3 | | -import { StaticPageRoutes } from './StaticPageRoutes'; |
4 | | -import { AuthRoutes } from './AuthRoutes'; |
5 | | -import { ProductRoutes } from './ProductRoutes'; |
| 3 | +import { PATH } from 'src/constants/paths'; |
| 4 | +import { Loading } from 'src/components/Loading'; |
| 5 | +import { AppHeader } from 'src/components/Header'; |
| 6 | +import { Route, Switch } from 'react-router-dom'; |
| 7 | +const NotFoundPage = lazy(() => import('src/pages/ErrorPages/404Pages')); |
| 8 | +const HomePage = lazy(() => import('src/pages/HomePages/HomePage')); |
| 9 | +const ContactPage = lazy(() => import('src/pages/StaticPages/ContactPage')); |
| 10 | +const AboutPage = lazy(() => import('src/pages/StaticPages/AboutPage')); |
| 11 | +const Demo1Page = lazy(() => import('src/pages/StaticPages/Demo1Page')); |
| 12 | +const Demo2Page = lazy(() => import('src/pages/StaticPages/Demo2Page')); |
| 13 | +const Feature1Page = lazy(() => import('src/pages/StaticPages/Feature1Page')); |
| 14 | +const Feature2Page = lazy(() => import('src/pages/StaticPages/Feature2Page')); |
| 15 | +const LoginPage = lazy(() => import('src/pages/AuthPages/LoginPage')); |
| 16 | +const RegisterPage = lazy(() => import('src/pages/AuthPages/RegisterPage')); |
| 17 | +const ProfilePage = lazy(() => import('src/pages/AuthPages/ProfilePage')); |
| 18 | +const ProductListPage = lazy( |
| 19 | + () => import('src/pages/ProductPages/ProductListPage'), |
| 20 | +); |
| 21 | +const ProductItemPage = lazy( |
| 22 | + () => import('src/pages/ProductPages/ProductItemPage'), |
| 23 | +); |
6 | 24 |
|
7 | 25 | export const Routes = () => { |
8 | 26 | return ( |
9 | | - <BrowserRouter> |
10 | | - <StaticPageRoutes /> |
11 | | - <AuthRoutes /> |
12 | | - <ProductRoutes /> |
13 | | - </BrowserRouter> |
| 27 | + <Suspense fallback={<Loading />}> |
| 28 | + <BrowserRouter> |
| 29 | + <Switch> |
| 30 | + {/* Static pages routes */} |
| 31 | + <Route exact path={PATH.HOME} component={HomePage} /> |
| 32 | + <Route exact path={PATH.ABOUT} component={AboutPage} /> |
| 33 | + <Route exact path={PATH.DEMO1} component={Demo1Page} /> |
| 34 | + <Route exact path={PATH.DEMO2} component={Demo2Page} /> |
| 35 | + <Route exact path={PATH.FEATURE1} component={Feature1Page} /> |
| 36 | + <Route exact path={PATH.FEATURE2} component={Feature2Page} /> |
| 37 | + <Route exact path={PATH.CONTACT} component={ContactPage} /> |
| 38 | + |
| 39 | + {/* Auth routes */} |
| 40 | + <Route exact path={PATH.LOGIN} component={LoginPage} /> |
| 41 | + <Route exact path={PATH.REGISTER} component={RegisterPage} /> |
| 42 | + <Route exact path={PATH.PROFILE} component={ProfilePage} /> |
| 43 | + |
| 44 | + {/* Products routes */} |
| 45 | + <Route exact path={PATH.PRODUCTS} component={ProductListPage} /> |
| 46 | + <Route |
| 47 | + exact |
| 48 | + path={PATH.PRODUCTS + '/:id'} |
| 49 | + component={ProductItemPage} |
| 50 | + /> |
| 51 | + |
| 52 | + {/* Error routes */} |
| 53 | + <Route component={NotFoundPage} /> |
| 54 | + </Switch> |
| 55 | + </BrowserRouter> |
| 56 | + </Suspense> |
14 | 57 | ); |
15 | 58 | }; |
0 commit comments