history.push reactjs code example

Example 1: react router dom push

import { useHistory } from "react-router-dom";

function HomeButton() {
  let history = useHistory();

  function handleClick() {
    history.push("/home");
  }

  return (
    
  );
}

Example 2: history.push

// usually all you need


// but you can use a location instead
const location = {
  pathname: '/somewhere',
  state: { fromDashboard: true }
}



history.push(location)
history.replace(location)

Example 3: history.pushstate

history.pushState(state, title[, url])

Tags:

Misc Example