1In react-router-dom version 6
2useHistory() is replaced by useNavigate() ;
3
4import {useNavigate} from 'react-router-dom';
5const navigate = useNavigate();
6navigate('/home')
1import React from "react";
2import ReactDOM from "react-dom";
3import {
4 BrowserRouter as Router,
5 Switch,
6 Route,
7 useParams
8} from "react-router-dom";
9
10function BlogPost() {
11 let { slug } = useParams();
12 return <div>Now showing post {slug}</div>;
13}
14
15ReactDOM.render(
16 <Router>
17 <Switch>
18 <Route exact path="/">
19 <HomePage />
20 </Route>
21 <Route path="/blog/:slug">
22 <BlogPost />
23 </Route>
24 </Switch>
25 </Router>,
26 node
27);
28