How to go back to home in React

Issue #665

Usually in header we have logo that takes user back to the home page

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// index.js
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from 'react-router-dom'

<Router>
<Switch>
<Route exact path="/">
<Home />
</Route>
</Router>
1
2
3
4
5
6
7
8
// Header.js

import { useHistory } from 'react-router-dom'
const history = useHistory()

<a class="navbar-item" onClick={() => {
history.push('/')
}}>

Comments