import { useHistory } from 'react-router-dom';
function Home() {
const history = useHistory();
return ;
}
Example 2: react router dom useparams
import React from "react";
import ReactDOM from "react-dom";
import {
BrowserRouter as Router,
Switch,
Route,
useParams
} from "react-router-dom";
function BlogPost() {
let { slug } = useParams();
return
Now showing post {slug}
;
}
ReactDOM.render(
,
node
);
Example 3: usehistory
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
);
}