Skip to content

Commit 3614262

Browse files
committed
refactor: update react router to v6
1 parent 80f931c commit 3614262

File tree

10 files changed

+78
-156
lines changed

10 files changed

+78
-156
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
"chart.js": "^3.7.0",
3737
"classnames": "^2.3.1",
3838
"core-js": "^3.20.2",
39-
"prop-types": "^15.8.0",
39+
"prop-types": "^15.8.1",
4040
"react": "^17.0.2",
4141
"react-app-polyfill": "^3.0.0",
4242
"react-dom": "^17.0.2",
4343
"react-redux": "^7.2.6",
44-
"react-router-dom": "^5.3.0",
44+
"react-router-dom": "^6.2.1",
4545
"redux": "4.1.2",
4646
"simplebar-react": "^2.3.6"
4747
},

src/App.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import React, { Component } from 'react'
2-
import { HashRouter, Route, Switch } from 'react-router-dom'
1+
import React, { Component, Suspense } from 'react'
2+
import { HashRouter, Navigate, Route, Routes } from 'react-router-dom'
3+
import { CSpinner } from '@coreui/react'
34
import './scss/style.scss'
45

5-
const loading = (
6-
<div className="pt-3 text-center">
7-
<div className="sk-spinner sk-spinner-pulse"></div>
8-
</div>
9-
)
6+
// routes config
7+
import routes from './routes'
108

119
// Containers
1210
const DefaultLayout = React.lazy(() => import('./layout/DefaultLayout'))
@@ -21,20 +19,30 @@ class App extends Component {
2119
render() {
2220
return (
2321
<HashRouter>
24-
<React.Suspense fallback={loading}>
25-
<Switch>
26-
<Route exact path="/login" name="Login Page" render={(props) => <Login {...props} />} />
27-
<Route
28-
exact
29-
path="/register"
30-
name="Register Page"
31-
render={(props) => <Register {...props} />}
32-
/>
33-
<Route exact path="/404" name="Page 404" render={(props) => <Page404 {...props} />} />
34-
<Route exact path="/500" name="Page 500" render={(props) => <Page500 {...props} />} />
35-
<Route path="/" name="Home" render={(props) => <DefaultLayout {...props} />} />
36-
</Switch>
37-
</React.Suspense>
22+
<Suspense fallback={<CSpinner color="primary" />}>
23+
<Routes>
24+
<Route exact path="/login" name="Login Page" element={<Login />} />
25+
<Route exact path="/register" name="Register Page" render={<Register />} />
26+
<Route exact path="/404" name="Page 404" element={<Page404 />} />
27+
<Route exact path="/500" name="Page 500" element={<Page500 />} />
28+
<Route path="/" name="Home" element={<DefaultLayout />}>
29+
<Route index element={<Navigate to="/dashboard" />} />
30+
{routes.map((route, idx) => {
31+
return (
32+
route.component && (
33+
<Route
34+
key={idx}
35+
path={route.path}
36+
exact={route.exact}
37+
name={route.name}
38+
element={<route.component />}
39+
/>
40+
)
41+
)
42+
})}
43+
</Route>
44+
</Routes>
45+
</Suspense>
3846
</HashRouter>
3947
)
4048
}

src/components/AppContent.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/AppHeader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const AppHeader = () => {
3636
</CHeaderBrand>
3737
<CHeaderNav className="d-none d-md-flex me-auto">
3838
<CNavItem>
39-
<CNavLink to="/dashboard" component={NavLink} activeClassName="active">
39+
<CNavLink to="/dashboard" component={NavLink}>
4040
Dashboard
4141
</CNavLink>
4242
</CNavItem>

src/components/AppSidebarNav.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const AppSidebarNav = ({ items }) => {
2828
{...(rest.to &&
2929
!rest.items && {
3030
component: NavLink,
31-
activeClassName: 'active',
3231
})}
3332
key={index}
3433
{...rest}

src/components/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import AppBreadcrumb from './AppBreadcrumb'
2-
import AppContent from './AppContent'
32
import AppFooter from './AppFooter'
43
import AppHeader from './AppHeader'
54
import AppHeaderDropdown from './header/AppHeaderDropdown'
@@ -10,7 +9,6 @@ import DocsExample from './DocsExample'
109

1110
export {
1211
AppBreadcrumb,
13-
AppContent,
1412
AppFooter,
1513
AppHeader,
1614
AppHeaderDropdown,

src/layout/DefaultLayout.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React from 'react'
2-
import { AppContent, AppSidebar, AppFooter, AppHeader } from '../components/index'
1+
import React, { Suspense } from 'react'
2+
import { Outlet } from 'react-router-dom'
3+
import { CContainer, CSpinner } from '@coreui/react'
4+
import { AppSidebar, AppFooter, AppHeader } from '../components/index'
35

46
const DefaultLayout = () => {
57
return (
@@ -8,7 +10,11 @@ const DefaultLayout = () => {
810
<div className="wrapper d-flex flex-column min-vh-100 bg-light">
911
<AppHeader />
1012
<div className="body flex-grow-1 px-3">
11-
<AppContent />
13+
<CContainer lg>
14+
<Suspense fallback={<CSpinner color="primary" />}>
15+
<Outlet />
16+
</Suspense>
17+
</CContainer>
1218
</div>
1319
<AppFooter />
1420
</div>

src/setupTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// allows you to do things like:
33
// expect(element).toHaveTextContent(/react/i)
44
// learn more: https://github.com/testing-library/jest-dom
5-
import '@testing-library/jest-dom';
5+
import '@testing-library/jest-dom'

src/views/dashboard/Dashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { lazy } from 'react'
1+
import React from 'react'
22

33
import {
44
CAvatar,

0 commit comments

Comments
 (0)