1import { useHistory } from "react-router-dom";
2
3function HomeButton() {
4 let history = useHistory();
5
6 function handleClick() {
7 history.push("/home");
8 }
9
10 return (
11 <Button type="button" onClick={handleClick}>
12 Go home
13 </Button>
14 );
15}
1history.push(
2 `/product?make=${car_make_id}&model=${car_model_id}&year=${car_generation_id}&series=${car_serie_id}&engine=${car_trim_id}&variant=${car_equipment_id}`
3 );
1class Comp extends React.Component {
2 componentDidUpdate(prevProps) {
3 // will be true
4 const locationChanged =
5 this.props.location !== prevProps.location;
6
7 // INCORRECT, will *always* be false because history is mutable.
8 const locationChanged =
9 this.props.history.location !== prevProps.history.location;
10 }
11}
12
13<Route component={Comp} />;
14
1{
2 key: 'ac3df4', // not with HashHistory!
3 pathname: '/somewhere',
4 search: '?some=search-string',
5 hash: '#howdy',
6 state: {
7 [userDefined]: true
8 }
9}
10