Skip to content

Commit 65f27aa

Browse files
committed
Prepare for React Router v6 upgrade
Guidance: https://reactrouter.com/en/main/upgrading/v5
1 parent 0d8d9bc commit 65f27aa

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/Layout/Public.js

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

src/Routes/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import React from 'react'
2-
import { Switch, Route } from 'react-router-dom'
3-
import Public from '../Layout/Public'
2+
import { Route, Switch, useLocation, useParams } from 'react-router-dom'
3+
44
import Forms from '../Components/forms'
55
import NotFound from '../Components/NotFound'
66

7+
function WithRouteProps({ children: Component }) {
8+
const location = useLocation()
9+
const params = useParams()
10+
return <Component location={location} match={{ params }} />
11+
}
12+
713
export default () => (
814
<Switch>
9-
<Public exact path="/" component={Forms} />
10-
<Public exact path="/code/:userId/:code?" component={Forms} />
11-
<Route path="*" component={NotFound} />
15+
<Route exact path="/">
16+
<WithRouteProps children={Forms} />
17+
</Route>
18+
<Route exact path="/code/:userId/:code?">
19+
<WithRouteProps children={Forms} />
20+
</Route>
21+
<Route path="*">
22+
<NotFound />
23+
</Route>
1224
</Switch>
1325
)

0 commit comments

Comments
 (0)