1import React from 'react';
2import { useHistory } from "react-router-dom";
3
4function Home() {
5 const history = useHistory();
6
7 const handleRoute = () =>{
8 history.push("/about");
9 }
10
11 return (
12 <Button
13 onClick={handleRoute}>
14 About
15 </Button>
16 );
17}
18export default Home;
1import { Route, Redirect } from 'react-router'
2
3<Route exact path="/" render={() => (
4 loggedIn ? (
5 <Redirect to="/dashboard"/>
6 ) : (
7 <PublicHomePage/>
8 )
9)}/>
1import { useHistory } from 'react-router-dom';
2
3function app() {
4 let history = useHistory();
5
6 const redirect = () => {
7 history.push('/your-path')
8 }
9
10 return (
11 <div>
12 <button onClick={redirect}>Redirect</button>
13 </div>
14 )
15}
1import { useHistory } from 'react-router-dom';
2
3function app() {
4 let history = useHistory();
5
6 const redirect = () => {
7 history.push('/your-path')
8 }
9
10 return (
11 <div>
12 <button onClick={redirect}>Redirect</button>
13 </div>
14 )
15}
16