forked from react-boilerplate/react-boilerplate-cra-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-boilerplate#15:fixed lazy loading add route card
- Loading branch information
Thinh922001
committed
Sep 27, 2024
1 parent
bb3ce17
commit 1177f6e
Showing
10 changed files
with
98 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import MyHeader from 'app/components/Header'; | ||
import { Main } from 'app/components/Main'; | ||
import { Outlet } from 'react-router-dom'; | ||
|
||
export const NoFooterLayout = () => { | ||
return ( | ||
<> | ||
<MyHeader /> | ||
<Main> | ||
<Outlet /> | ||
</Main> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import { lazyLoad } from 'utils/loadable'; | ||
import { LoadingIndicator } from 'app/components/LoadingIndicator'; | ||
import styled from 'styled-components/macro'; | ||
|
||
const LoadingWrapper = styled.div` | ||
width: 100%; | ||
height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
export const LZCardPage = lazyLoad( | ||
() => import('./index'), | ||
module => module.CardPage, | ||
{ | ||
fallback: ( | ||
<LoadingWrapper> | ||
<LoadingIndicator /> | ||
</LoadingWrapper> | ||
), | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Helmet } from 'react-helmet-async'; | ||
|
||
export function CardPage() { | ||
return ( | ||
<> | ||
<Helmet> | ||
<title>Giỏ hàng</title> | ||
<meta name="description" content="Giỏ hàng" /> | ||
</Helmet> | ||
<div> | ||
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem natus | ||
dolor ullam rerum amet. Modi officiis ratione ullam numquam totam | ||
expedita ducimus iusto, molestiae quasi autem voluptatum repellat | ||
minima? Voluptas? | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MainLayout } from './layout/main-layout'; | ||
import { NotFoundPage } from './pages/NotFoundPage'; | ||
import { LZMyHomePage } from './pages/MyHomePage/Loadable'; | ||
import { NoFooterLayout } from './layout/no-footer'; | ||
import { LZCardPage } from './pages/CardPage/Loadable'; | ||
import { RouteObject, useRoutes } from 'react-router-dom'; | ||
import React from 'react'; | ||
|
||
const routes: RouteObject[] = [ | ||
{ | ||
path: '/', | ||
element: <MainLayout />, | ||
children: [{ index: true, element: <LZMyHomePage /> }], | ||
}, | ||
{ | ||
path: '/card', | ||
element: <NoFooterLayout />, | ||
children: [{ index: true, element: <LZCardPage /> }], | ||
}, | ||
{ path: '*', element: <NotFoundPage /> }, | ||
]; | ||
|
||
const AppRoutes: React.FC = () => { | ||
const element = useRoutes(routes); | ||
return element; | ||
}; | ||
|
||
export default AppRoutes; |