Skip to content

Commit e9a2c64

Browse files
feat: upgrade react router to v6 (#243)
* feat: upgrade react router to v6 * refactor: convert scrollToTop to functional component
1 parent 9e2a32a commit e9a2c64

File tree

4 files changed

+76
-136
lines changed

4 files changed

+76
-136
lines changed

package-lock.json

Lines changed: 28 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"prop-types": "15.8.1",
4646
"react": "17.0.2",
4747
"react-dom": "17.0.2",
48-
"react-router-dom": "5.3.4",
48+
"react-router-dom": "6.14.2",
4949
"react-router-hash-link": "1.2.2",
5050
"react-scripts": "5.0.1",
5151
"semantic-release": "^20.1.3"

src/App.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { BrowserRouter, Route, NavLink } from 'react-router-dom';
2+
import { BrowserRouter, Route, NavLink, Routes } from 'react-router-dom';
33
import { HashLink } from 'react-router-hash-link';
44

55
import Basics from './pages/Basics';
@@ -154,47 +154,48 @@ class App extends Component {
154154
</li>
155155
</ul>
156156
</div>
157+
<Routes>
158+
<Route path="/" element={<Overview />} />
159+
<Route path="/GettingStarted" element={<GettingStarted />} />
160+
<Route path="/Basics" element={<Basics />} />
157161

158-
<Route exact path="/" component={Overview} />
159-
<Route exact path="/GettingStarted" component={GettingStarted} />
160-
<Route exact path="/Basics" component={Basics} />
162+
{/* Basics */}
163+
<Route path="/Basics#colors" element={<Basics />} />
164+
<Route path="/Basics#typography" element={<Basics />} />
165+
<Route path="/Basics#buttons" element={<Basics />} />
166+
<Route path="/Basics#icons" element={<Basics />} />
167+
<Route path="/Basics#themes" element={<Basics />} />
161168

162-
{/* Basics */}
163-
<Route path="/Basics#colors" component={Basics} />
164-
<Route path="/Basics#typography" component={Basics} />
165-
<Route path="/Basics#buttons" component={Basics} />
166-
<Route path="/Basics#icons" component={Basics} />
167-
<Route path="/Basics#themes" component={Basics} />
169+
{/* Navigation */}
170+
<Route exact path="/Navigation" element={<Navigation />} />
171+
<Route path="/Navigation#links" element={<Navigation />} />
172+
<Route path="/Navigation#breadcrumbs" element={<Navigation />} />
173+
<Route path="/Navigation#tabs" element={<Navigation />} />
174+
<Route path="/Navigation#search" element={<Navigation />} />
168175

169-
{/* Navigation */}
170-
<Route exact path="/Navigation" component={Navigation} />
171-
<Route path="/Navigation#links" component={Navigation} />
172-
<Route path="/Navigation#breadcrumbs" component={Navigation} />
173-
<Route path="/Navigation#tabs" component={Navigation} />
174-
<Route path="/Navigation#search" component={Navigation} />
176+
{/* Content */}
177+
<Route path="/Forms" element={<Forms />} />
178+
<Route path="/Cards" element={<Cards />} />
179+
<Route path="/Alerts" element={<Alerts />} />
180+
<Route path="/Badge" element={<Badge />} />
181+
<Route path="/Dropdowns" element={<Dropdowns />} />
182+
<Route path="/Modal" element={<Modal />} />
183+
<Route path="/Pagination" element={<Pagination />} />
184+
<Route path="/Tables" element={<Tables />} />
175185

176-
{/* Content */}
177-
<Route path="/Forms" component={Forms} />
178-
<Route path="/Cards" component={Cards} />
179-
<Route path="/Alerts" component={Alerts} />
180-
<Route path="/Badge" component={Badge} />
181-
<Route path="/Dropdowns" component={Dropdowns} />
182-
<Route path="/Modal" component={Modal} />
183-
<Route path="/Pagination" component={Pagination} />
184-
<Route path="/Tables" component={Tables} />
186+
{/* Miscellaneous */}
187+
<Route exact path="/Miscellaneous" element={<Miscellaneous />} />
188+
<Route path="/Miscellaneous#loaders" element={<Miscellaneous />} />
185189

186-
{/* Miscellaneous */}
187-
<Route exact path="/Miscellaneous" component={Miscellaneous} />
188-
<Route path="/Miscellaneous#loaders" component={Miscellaneous} />
190+
{/* Examples */}
191+
<Route path="/Examples" element={<Examples />} />
189192

190-
{/* Examples */}
191-
<Route path="/Examples" component={Examples} />
192-
193-
{/* Bootstrap documentation pages */}
194-
<Route path="/Bootstrap/Collapse" component={Collapse} />
195-
<Route path="/Bootstrap/Grid" component={Grid} />
196-
<Route path="/Bootstrap/Popovers" component={Popovers} />
197-
<Route path="/Bootstrap/Progress" component={Progress} />
193+
{/* Bootstrap documentation pages */}
194+
<Route path="/Bootstrap/Collapse" element={<Collapse />} />
195+
<Route path="/Bootstrap/Grid" element={<Grid />} />
196+
<Route path="/Bootstrap/Popovers" element={<Popovers />} />
197+
<Route path="/Bootstrap/Progress" element={<Progress />} />
198+
</Routes>
198199
</div>
199200
</div>
200201
</div>

src/ScrollToTop.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { Component } from 'react';
2-
import { withRouter } from 'react-router-dom';
1+
import { useEffect } from 'react';
2+
import { useLocation } from 'react-router-dom';
33

4-
class ScrollToTop extends Component {
5-
componentDidUpdate(prevProps) {
6-
if (this.props.location.pathname !== prevProps.location.pathname) {
7-
window.scrollTo(0, 0);
8-
}
9-
}
4+
const ScrollToTop = ({ children }) => {
5+
const location = useLocation();
106

11-
render() {
12-
return this.props.children;
13-
}
7+
useEffect(() => {
8+
window.scrollTo(0, 0);
9+
}, [location.pathname]);
10+
11+
return children;
1412
}
1513

16-
export default withRouter(ScrollToTop);
14+
export default ScrollToTop;

0 commit comments

Comments
 (0)