Skip to content

Commit ea1e44d

Browse files
author
Ronald van der Kooij
committed
using strict mode with react router 6
1 parent 07f3d86 commit ea1e44d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/App.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import './App.css';
33

44
import Layout from './Layout/Layout';
55

6-
import { BrowserRouter as Router } from 'react-router-dom';
6+
import { BrowserRouter } from 'react-router-dom';
77
const App: React.FC = () => {
88
return (
9-
<div>
10-
<Router>
11-
<Layout />
12-
</Router>
13-
</div>
9+
<React.StrictMode>
10+
<div>
11+
<BrowserRouter>
12+
<Layout />
13+
</BrowserRouter>
14+
</div>
15+
</React.StrictMode>
1416
);
1517
};
1618

src/Layout/PageContent.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import React from 'react';
2-
import { Switch, Route } from 'react-router-dom';
2+
import { Routes, Route } from 'react-router-dom';
33
import { examplesList } from '../examples/examplesList';
44

55
const PageContent = () => {
66
return (
77
<div className="content-page">
8-
<Switch>
8+
<Routes>
99
{examplesList.map((item) => (
10-
<Route key={item.name} exact={item.exact} path={item.path}>
11-
<React.Fragment>
12-
<h1>{item.name}</h1>
13-
{<item.component />}
14-
</React.Fragment>
15-
</Route>
10+
<Route
11+
key={item.name}
12+
path={item.path}
13+
element={
14+
<>
15+
<h1>{item.name}</h1>
16+
{<item.component />}
17+
</>
18+
}
19+
></Route>
1620
))}
17-
</Switch>
21+
</Routes>
1822
</div>
1923
);
2024
};

src/Layout/Sidebar.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import React from 'react';
1+
import React, { FC } from 'react';
22
import List from '@mui/material/List';
33
import ListItem from '@mui/material/ListItem';
44
import ListItemText from '@mui/material/ListItemText';
55
import { Link } from 'react-router-dom';
66
import { examplesList } from '../examples/examplesList';
7-
import { withRouter, RouteProps } from 'react-router';
7+
import { useLocation } from 'react-router';
8+
9+
const Sidebar: FC = () => {
10+
const location = useLocation();
811

9-
const Sidebar = ({ location }: RouteProps) => {
1012
return (
1113
<div className="sidebar">
1214
<List disablePadding dense>
@@ -26,4 +28,4 @@ const Sidebar = ({ location }: RouteProps) => {
2628
);
2729
};
2830

29-
export default withRouter(Sidebar);
31+
export default Sidebar;

0 commit comments

Comments
 (0)