Answers for "Programmatically navigate using react router"

4

navigating programatically react

import { Route } from 'react-router-dom'

const Button = () => (
  <Route render={({ history}) => (
    <button
      type='button'
      onClick={() => { history.push('/new-location') }}
    >
      Click Me!
    </button>
  )} />
)
Posted by: Guest on July-01-2020
0

Programmatically navigate using react router

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

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

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

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  );
}
Posted by: Guest on November-28-2019

Code answers related to "Programmatically navigate using react router"

Code answers related to "Javascript"

Browse Popular Code Answers by Language